pub struct LruCache<K, V> { /* private fields */ }Expand description
A generic LRU cache with configurable max size and TTL.
Thread-safe via internal RwLock. Expired entries are lazily evicted on access.
Implementations§
Source§impl<K, V> LruCache<K, V>
impl<K, V> LruCache<K, V>
Sourcepub fn new(max_size: usize, ttl: Duration) -> Self
pub fn new(max_size: usize, ttl: Duration) -> Self
Create a new LRU cache with the given capacity and TTL.
Sourcepub fn from_config(config: &LruCacheConfig) -> Self
pub fn from_config(config: &LruCacheConfig) -> Self
Create from a serializable config.
Sourcepub fn get(&self, key: &K) -> Option<V>
pub fn get(&self, key: &K) -> Option<V>
Get a value by key. Returns None if missing or expired.
Sourcepub fn insert(&self, key: K, value: V)
pub fn insert(&self, key: K, value: V)
Insert a key-value pair. Evicts the LRU entry if at capacity.
Sourcepub fn invalidate(&self, key: &K) -> bool
pub fn invalidate(&self, key: &K) -> bool
Invalidate (remove) a specific key.
Sourcepub fn metrics(&self) -> &CacheMetrics
pub fn metrics(&self) -> &CacheMetrics
Access the cache metrics.
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>
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