Struct memory_lru::MemoryLruCache
source · pub struct MemoryLruCache<K, V> { /* private fields */ }
Expand description
An LRU-cache which operates on memory used.
Implementations§
source§impl<K: Eq + Hash, V: ResidentSize> MemoryLruCache<K, V>
impl<K: Eq + Hash, V: ResidentSize> MemoryLruCache<K, V>
sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new cache with a maximum cumulative size of values.
sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Get a reference to an item in the cache. It is a logic error for its heap size to be altered while borrowed.
sourcepub fn with_mut<U>(
&mut self,
key: &K,
with: impl FnOnce(Option<&mut V>) -> U
) -> U
pub fn with_mut<U>(
&mut self,
key: &K,
with: impl FnOnce(Option<&mut V>) -> U
) -> U
Execute a closure with the value under the provided key.
sourcepub fn current_size(&self) -> usize
pub fn current_size(&self) -> usize
Currently-used size of values in bytes.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of key-value pairs that are currently in the cache.