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.
Auto Trait Implementations§
impl<K, V> Freeze for MemoryLruCache<K, V>
impl<K, V> RefUnwindSafe for MemoryLruCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for MemoryLruCache<K, V>
impl<K, V> Sync for MemoryLruCache<K, V>
impl<K, V> Unpin for MemoryLruCache<K, V>
impl<K, V> UnwindSafe for MemoryLruCache<K, V>
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
Mutably borrows from an owned value. Read more