pub struct LruCache<K, V> { /* private fields */ }Expand description
Thread-safe LRU cache using DashMap with approximate LRU eviction.
Uses an atomic counter for access ordering instead of timestamps, providing better performance while maintaining approximate LRU semantics.
Implementations§
Source§impl<K: Hash + Eq + Clone, V: Clone> LruCache<K, V>
impl<K: Hash + Eq + Clone, V: Clone> LruCache<K, V>
pub fn new(capacity: usize) -> Self
Sourcepub fn get(&self, key: &K) -> Option<V>
pub fn get(&self, key: &K) -> Option<V>
Get a value and update LRU order. Returns cloned value.
Sourcepub fn put(&self, key: K, value: V) -> Option<V>
pub fn put(&self, key: K, value: V) -> Option<V>
Put a value into the cache. Returns old value if key existed.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Check if cache contains a key (read-only, doesn’t update LRU order).
Auto Trait Implementations§
impl<K, V> !Freeze for LruCache<K, V>
impl<K, V> !RefUnwindSafe for LruCache<K, V>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more