pub struct AssetCache { /* private fields */ }Expand description
LRU eviction cache that sits on top of AssetRegistry.
When the cache is full, the least-recently-used asset is evicted from the
registry. Assets held by live AssetHandles will not be collected by
the OS even after eviction, but the registry entry is removed so the next
request will trigger a reload.
Capacity is measured in number of assets, not bytes.
Implementations§
Source§impl AssetCache
impl AssetCache
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new cache with the given capacity.
A capacity of 0 disables eviction (unlimited).
Sourcepub fn touch(&mut self, id: u64) -> Option<u64>
pub fn touch(&mut self, id: u64) -> Option<u64>
Notify the cache that id was accessed.
Moves id to the most-recently-used position and returns any ID that
should now be evicted (the least-recently-used), or None.
Sourcepub fn remove(&mut self, id: u64)
pub fn remove(&mut self, id: u64)
Remove id from the tracking queue (called after explicit eviction).
Sourcepub fn set_capacity(&mut self, new_cap: usize) -> Vec<u64>
pub fn set_capacity(&mut self, new_cap: usize) -> Vec<u64>
Change the capacity. If the new capacity is smaller, returns a list of IDs that must be evicted immediately.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AssetCache
impl RefUnwindSafe for AssetCache
impl Send for AssetCache
impl Sync for AssetCache
impl Unpin for AssetCache
impl UnsafeUnpin for AssetCache
impl UnwindSafe for AssetCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.