pub struct SharedLRUCache<K: Copy + Eq + Default + 'static, V: Copy + Default + 'static> { /* private fields */ }Implementations§
Sourcepub fn create(
base_path: impl AsRef<Path>,
capacity: u32,
) -> Result<Self, LRUError>
pub fn create( base_path: impl AsRef<Path>, capacity: u32, ) -> Result<Self, LRUError>
Create a new LRU cache with capacity entries.
SIZING: the underlying SharedHashMap is sized to 8x capacity to absorb tombstone accumulation (open-addressing leaves a tombstone on every remove; LRU caches do many removes via eviction). The linked list region is sized to capacity + 2 (one sentinel head + capacity nodes + 1 spare for the pop-then-push transition during update).
pub fn open( base_path: impl AsRef<Path>, capacity: u32, ) -> Result<Self, LRUError>
pub fn capacity(&self) -> u32
pub fn is_empty(&self) -> bool
Sourcepub fn get(&self, key: &K) -> Option<V>
pub fn get(&self, key: &K) -> Option<V>
Lock-free lookup. Does NOT promote k to MRU position.
Use get_and_touch or
touch for strict LRU semantics.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
True if key is present (lock-free).
Sourcepub fn touch(&self, key: &K) -> bool
pub fn touch(&self, key: &K) -> bool
Promote key to MRU position. Writer-side. Returns true if
the key was present and was promoted.
Sourcepub fn get_and_touch(&self, key: &K) -> Option<V>
pub fn get_and_touch(&self, key: &K) -> Option<V>
Look up and promote in one call. Writer-side.
Sourcepub fn put(&self, key: K, value: V) -> Result<Option<V>, LRUError>
pub fn put(&self, key: K, value: V) -> Result<Option<V>, LRUError>
Insert / update. Writer-side. If the cache is at capacity
AND key is new, evicts the LRU entry first. Returns the
previous value if key was present.
Sourcepub fn remove(&self, key: &K) -> Option<V>
pub fn remove(&self, key: &K) -> Option<V>
Remove a key. Writer-side. Returns the value if present.
Sourcepub fn evict_oldest(&self) -> Option<(K, V)>
pub fn evict_oldest(&self) -> Option<(K, V)>
Evict the LRU (least-recently-used) entry. Writer-side. Returns (key, value) of the evicted entry, or None if empty.
Sourcepub fn snapshot_mru_first(&self) -> Vec<(K, V)>
pub fn snapshot_mru_first(&self) -> Vec<(K, V)>
Snapshot all entries from MRU (front) to LRU (back). Lock-free; not stable under concurrent writers.
Sourcepub fn snapshot_lru_first(&self) -> Vec<(K, V)>
pub fn snapshot_lru_first(&self) -> Vec<(K, V)>
Snapshot all entries from LRU (back) to MRU (front).