pub struct Cache<K, V> { /* private fields */ }
Expand description
A not so accurate but performant time and capacity based cache.
Implementations§
Source§impl<K, V> Cache<K, V>
impl<K, V> Cache<K, V>
Sourcepub fn new(capacity: usize, ttl: Duration) -> Self
pub fn new(capacity: usize, ttl: Duration) -> Self
Create a new cache with the given capacity and time-to-live (TTL) for values.
Sourcepub fn get(&self, key: &K) -> Option<Value<V>>
pub fn get(&self, key: &K) -> Option<Value<V>>
Get the value associated with the given key, if it exists and is not expired.
Sourcepub fn insert(&self, key: K, value: V)
pub fn insert(&self, key: K, value: V)
Insert a key-value pair in the cache.
If the cache is full, it will evict the oldest entry.
pub fn remove(&self, key: &K) -> Option<V>
pub fn clear(&self)
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>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