pub struct MemoryCache<K: Hash, T: Clone> { /* private fields */ }
Expand description
A high performant in-memory cache with S3-FIFO + TinyLFU
Implementations§
Source§impl<K: Hash, T: Clone + Send + Sync + 'static> MemoryCache<K, T>
impl<K: Hash, T: Clone + Send + Sync + 'static> MemoryCache<K, T>
Sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Create a new MemoryCache with the given size.
Sourcepub fn get<Q>(&self, key: &Q) -> (Option<T>, CacheStatus)
pub fn get<Q>(&self, key: &Q) -> (Option<T>, CacheStatus)
Fetch the key and return its value in addition to a CacheStatus.
Sourcepub fn get_stale<Q>(&self, key: &Q) -> (Option<T>, CacheStatus)
pub fn get_stale<Q>(&self, key: &Q) -> (Option<T>, CacheStatus)
Similar to Self::get, fetch the key and return its value in addition to a CacheStatus but also return the value even if it is expired. When the value is expired, the Duration of how long it has been stale will also be returned.
Sourcepub fn put<Q>(&self, key: &Q, value: T, ttl: Option<Duration>)
pub fn put<Q>(&self, key: &Q, value: T, ttl: Option<Duration>)
Insert a key and value pair with an optional TTL into the cache.
An item with zero TTL of zero will not be inserted.
Sourcepub fn multi_get<'a, I, Q>(&self, keys: I) -> Vec<(Option<T>, CacheStatus)>
pub fn multi_get<'a, I, Q>(&self, keys: I) -> Vec<(Option<T>, CacheStatus)>
This is equivalent to MemoryCache::get but for an arbitrary amount of keys.
Sourcepub fn multi_get_with_miss<'a, I, Q>(
&self,
keys: I,
) -> (Vec<(Option<T>, CacheStatus)>, Vec<&'a Q>)
pub fn multi_get_with_miss<'a, I, Q>( &self, keys: I, ) -> (Vec<(Option<T>, CacheStatus)>, Vec<&'a Q>)
Same as MemoryCache::multi_get but returns the keys that are missing from the cache.
Auto Trait Implementations§
impl<K, T> !Freeze for MemoryCache<K, T>
impl<K, T> !RefUnwindSafe for MemoryCache<K, T>
impl<K, T> Send for MemoryCache<K, T>
impl<K, T> Sync for MemoryCache<K, T>
impl<K, T> Unpin for MemoryCache<K, T>
impl<K, T> !UnwindSafe for MemoryCache<K, T>
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