Struct generational_lru::lrucache::LRUCache
source · [−]pub struct LRUCache<K, V> where
K: Eq + Hash, {
blocks: LinkedList<Block<K, V>>,
block_refs: HashMap<K, Link>,
}
Expand description
A Least-Recently-Used (LRU) Cache implemented using a generational arena based linked list and a hash map.
Fields
blocks: LinkedList<Block<K, V>>
block_refs: HashMap<K, Link>
Implementations
sourceimpl<K, V> LRUCache<K, V> where
K: Eq + Hash + Copy,
impl<K, V> LRUCache<K, V> where
K: Eq + Hash + Copy,
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an LRUCache instance with the given capacity. A zero capacity LRUCache is unusable.
sourcepub fn query(&mut self, key: &K) -> Result<&V, CacheError>
pub fn query(&mut self, key: &K) -> Result<&V, CacheError>
Returns a reference to the value associated with the given key. If the key is not present in the cache, we return a “cache-miss” error. If the entry is found but cannot be fetched from the underlying storage, we return a “cache-broken” error.
sourcepub fn remove(&mut self, key: &K) -> Result<V, CacheError>
pub fn remove(&mut self, key: &K) -> Result<V, CacheError>
Removes the associated key value pair for the given key from this cache. If no entry is found, we return a “cache-miss” error. If the entry is found but cannot be fetched from the underlying in-memory storage, we return a “cache-broken” error. Returns the value associated, after removal with ownership.
sourcepub fn insert(&mut self, key: K, value: V) -> Result<(), CacheError>
pub fn insert(&mut self, key: K, value: V) -> Result<(), CacheError>
Inserts a new key value pair into this cache. If this cache is full, the least recently used entry is removed.
Auto Trait Implementations
impl<K, V> RefUnwindSafe for LRUCache<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for LRUCache<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for LRUCache<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for LRUCache<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for LRUCache<K, V> where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more