pub struct LruCache<K: Eq + Hash + Clone, V: Clone> { /* private fields */ }Expand description
Bounded LRU cache. Eviction is O(N) per insert in the worst case (we scan the access order), but N is the cache capacity — small in practice (≤4096 for the remoting use case).
Implementations§
Source§impl<K: Eq + Hash + Clone, V: Clone> LruCache<K, V>
impl<K: Eq + Hash + Clone, V: Clone> LruCache<K, V>
pub fn new(capacity: usize) -> Self
pub fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn contains(&self, key: &K) -> bool
Sourcepub fn get(&mut self, key: &K) -> Option<V>
pub fn get(&mut self, key: &K) -> Option<V>
Look up key, bumping its recency. Returns None on miss.
Sourcepub fn put(&mut self, key: K, value: V) -> Option<V>
pub fn put(&mut self, key: K, value: V) -> Option<V>
Insert (key, value). Evicts the least-recently-used entry
when at capacity. Returns the evicted value if any.
pub fn remove(&mut self, key: &K) -> Option<V>
pub fn clear(&mut self)
Auto Trait Implementations§
impl<K, V> Freeze for LruCache<K, V>
impl<K, V> RefUnwindSafe for LruCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for LruCache<K, V>
impl<K, V> Sync for LruCache<K, V>
impl<K, V> Unpin for LruCache<K, V>
impl<K, V> UnsafeUnpin for LruCache<K, V>
impl<K, V> UnwindSafe for LruCache<K, V>where
K: UnwindSafe,
V: UnwindSafe,
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