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(&self, key: &K) -> (Option<T>, CacheStatus)
pub fn get(&self, key: &K) -> (Option<T>, CacheStatus)
Fetch the key and return its value in addition to a CacheStatus.
Sourcepub fn put(&self, key: &K, value: T, ttl: Option<Duration>)
pub fn put(&self, key: &K, 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>(&self, keys: I) -> Vec<(Option<T>, CacheStatus)>
pub fn multi_get<'a, I>(&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>(
&self,
keys: I,
) -> (Vec<(Option<T>, CacheStatus)>, Vec<&'a K>)
pub fn multi_get_with_miss<'a, I>( &self, keys: I, ) -> (Vec<(Option<T>, CacheStatus)>, Vec<&'a K>)
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