pub struct Cache<K, V> { /* private fields */ }
Expand description
High-performance in-memory cache with TTL and LRU eviction
Implementations§
Source§impl<K: Hash + Eq + Clone, V: Clone> Cache<K, V>
impl<K: Hash + Eq + Clone, V: Clone> Cache<K, V>
Sourcepub fn with_ttl(max_size: usize, default_ttl: Duration) -> Self
pub fn with_ttl(max_size: usize, default_ttl: Duration) -> Self
Create a new cache with TTL support
Sourcepub async fn insert(&self, key: K, value: V, ttl: Option<Duration>)
pub async fn insert(&self, key: K, value: V, ttl: Option<Duration>)
Insert a value with optional custom TTL
Sourcepub async fn contains_key(&self, key: &K) -> bool
pub async fn contains_key(&self, key: &K) -> bool
Check if a key exists in the cache (without updating access stats)
Sourcepub async fn stats(&self) -> CacheStats
pub async fn stats(&self) -> CacheStats
Get cache statistics
Sourcepub async fn reset_stats(&self)
pub async fn reset_stats(&self)
Reset cache statistics
Sourcepub async fn get_or_insert<F, Fut>(&self, key: K, f: F) -> V
pub async fn get_or_insert<F, Fut>(&self, key: K, f: F) -> V
Get or insert a value using a closure
Sourcepub async fn get_or_insert_with_ttl<F, Fut>(
&self,
key: K,
f: F,
ttl: Duration,
) -> V
pub async fn get_or_insert_with_ttl<F, Fut>( &self, key: K, f: F, ttl: Duration, ) -> V
Get or insert a value with custom TTL using a closure
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for Cache<K, V>
impl<K, V> !RefUnwindSafe for Cache<K, V>
impl<K, V> Send for Cache<K, V>
impl<K, V> Sync for Cache<K, V>
impl<K, V> Unpin for Cache<K, V>
impl<K, V> !UnwindSafe for Cache<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