pub struct Cache<K, V> { /* private fields */ }Expand description
A thread-safe cache with TTL support.
Implementations§
Source§impl<K, V> Cache<K, V>
impl<K, V> Cache<K, V>
Sourcepub fn new(default_ttl: Duration, max_size: usize) -> Self
pub fn new(default_ttl: Duration, max_size: usize) -> Self
Create a new cache with the given default TTL and maximum size.
Sourcepub async fn put_with_ttl(&self, key: K, value: V, ttl: Duration)
pub async fn put_with_ttl(&self, key: K, value: V, ttl: Duration)
Put a value into the cache with custom TTL.
Sourcepub async fn stats(&self) -> CacheStats
pub async fn stats(&self) -> CacheStats
Get cache statistics.
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> UnsafeUnpin 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