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.