Struct generational_cache::cache::lru_cache::LRUCache   
source · pub struct LRUCache<V, K, T, M> { /* private fields */ }Expand description
A generational Arena backed LRU cache implementation.
This Cache implementation always evicts the least-recently-used (LRU) key/value pair. It
uses a LinkedList for storing the underlying cache block entries to maintain the order
in which they were inserted into the cache.
It uses a generational Arena for allocating the underlying
LinkedList which stores the cache blocks. It uses a Map for maintaining the mapping
from keys to the nodes storing the respective cache blocks in the LinkedList.
Type parameters
- V: Vector<LRUCacheBlockArenaEntry<K, T>>Used as the backing vector for the underlying- Arena.
- KThe Key type.
- VThe Value type.
- M: Map<K, Link>Used to store a mapping from the keys to links in the linked list.
Implementations§
source§impl<V, K, T, M> LRUCache<V, K, T, M>where
    V: Vector<LRUCacheBlockArenaEntry<K, T>>,
    M: Map<K, Link>,
 
impl<V, K, T, M> LRUCache<V, K, T, M>where V: Vector<LRUCacheBlockArenaEntry<K, T>>, M: Map<K, Link>,
sourcepub fn least_recent(&self) -> Option<(&K, &T)>
 
pub fn least_recent(&self) -> Option<(&K, &T)>
Returns the least recently used key/value pair.
sourcepub fn most_recent(&self) -> Option<(&K, &T)>
 
pub fn most_recent(&self) -> Option<(&K, &T)>
Returns the most recently used key/value pair.
source§impl<V, K, T, M> LRUCache<V, K, T, M>where
    V: Vector<LRUCacheBlockArenaEntry<K, T>>,
    M: Map<K, Link>,
 
impl<V, K, T, M> LRUCache<V, K, T, M>where V: Vector<LRUCacheBlockArenaEntry<K, T>>, M: Map<K, Link>,
sourcepub fn with_backing_vector_and_map(vector: V, map: M) -> Self
 
pub fn with_backing_vector_and_map(vector: V, map: M) -> Self
Trait Implementations§
source§impl<V, K, T, M> Cache<K, T> for LRUCache<V, K, T, M>where
    V: Vector<LRUCacheBlockArenaEntry<K, T>>,
    M: Map<K, Link>,
    K: Copy,
 
impl<V, K, T, M> Cache<K, T> for LRUCache<V, K, T, M>where V: Vector<LRUCacheBlockArenaEntry<K, T>>, M: Map<K, Link>, K: Copy,
§type Error = LRUCacheError<<V as Vector<Entry<Node<Block<K, T>>>>>::Error, <M as Map<K, Link>>::Error>
 
type Error = LRUCacheError<<V as Vector<Entry<Node<Block<K, T>>>>>::Error, <M as Map<K, Link>>::Error>
Associated error type.
source§fn insert(&mut self, key: K, value: T) -> Result<Eviction<K, T>, Self::Error>
 
fn insert(&mut self, key: K, value: T) -> Result<Eviction<K, T>, Self::Error>
Inserts the given key/value pair into this cache.
source§fn remove(&mut self, key: &K) -> Result<Lookup<T>, Self::Error>
 
fn remove(&mut self, key: &K) -> Result<Lookup<T>, Self::Error>
Removes the key/value pair associated with the given key from this cache.
source§fn shrink(&mut self, new_capacity: usize) -> Result<(), Self::Error>
 
fn shrink(&mut self, new_capacity: usize) -> Result<(), Self::Error>
Removes 
(self.len() - new_capacity) cache blocks to fit the new capacity. If the
difference is non-positive no cache blocks are removed.source§fn reserve(&mut self, additional: usize) -> Result<(), Self::Error>
 
fn reserve(&mut self, additional: usize) -> Result<(), Self::Error>
Reserves additional memory to accomodate the given number of additional cache blocks.
source§fn query(&mut self, key: &K) -> Result<Lookup<&T>, Self::Error>
 
fn query(&mut self, key: &K) -> Result<Lookup<&T>, Self::Error>
Queries this cache to find the value associated with given key.
Auto Trait Implementations§
impl<V, K, T, M> RefUnwindSafe for LRUCache<V, K, T, M>where K: RefUnwindSafe, M: RefUnwindSafe, T: RefUnwindSafe, V: RefUnwindSafe,
impl<V, K, T, M> Send for LRUCache<V, K, T, M>where K: Send, M: Send, T: Send, V: Send,
impl<V, K, T, M> Sync for LRUCache<V, K, T, M>where K: Sync, M: Sync, T: Sync, V: Sync,
impl<V, K, T, M> Unpin for LRUCache<V, K, T, M>where K: Unpin, M: Unpin, T: Unpin, V: Unpin,
impl<V, K, T, M> UnwindSafe for LRUCache<V, K, T, M>where K: UnwindSafe, M: UnwindSafe, T: 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