Struct cached::stores::ExpiringValueCache
source · [−]Expand description
Expiring Value Cache
Stores values that implement the CanExpire trait so that expiration is determined by the values themselves. This is useful for caching values which themselves contain an expiry timestamp.
Note: This cache is in-memory only.
Implementations
sourceimpl<K: Clone + Hash + Eq, V: CanExpire> ExpiringValueCache<K, V>
impl<K: Clone + Hash + Eq, V: CanExpire> ExpiringValueCache<K, V>
sourcepub fn with_size(size: usize) -> ExpiringValueCache<K, V>
pub fn with_size(size: usize) -> ExpiringValueCache<K, V>
Creates a new ExpiringValueCache
with a given size limit and
pre-allocated backing data.
Trait Implementations
sourceimpl<K: Hash + Eq + Clone, V: CanExpire> Cached<K, V> for ExpiringValueCache<K, V>
impl<K: Hash + Eq + Clone, V: CanExpire> Cached<K, V> for ExpiringValueCache<K, V>
sourcefn cache_get_mut(&mut self, k: &K) -> Option<&mut V>
fn cache_get_mut(&mut self, k: &K) -> Option<&mut V>
Attempt to retrieve a cached value with mutable access
sourcefn cache_get_or_set_with<F: FnOnce() -> V>(&mut self, k: K, f: F) -> &mut V
fn cache_get_or_set_with<F: FnOnce() -> V>(&mut self, k: K, f: F) -> &mut V
Get or insert a key, value pair
sourcefn cache_set(&mut self, k: K, v: V) -> Option<V>
fn cache_set(&mut self, k: K, v: V) -> Option<V>
Insert a key, value pair and return the previous value
sourcefn cache_remove(&mut self, k: &K) -> Option<V>
fn cache_remove(&mut self, k: &K) -> Option<V>
Remove a cached value
sourcefn cache_clear(&mut self)
fn cache_clear(&mut self)
Remove all cached values. Keeps the allocated memory for reuse.
sourcefn cache_reset(&mut self)
fn cache_reset(&mut self)
Remove all cached values. Free memory and return to initial state
sourcefn cache_size(&self) -> usize
fn cache_size(&self) -> usize
Return the current cache size (number of elements)
sourcefn cache_hits(&self) -> Option<u64>
fn cache_hits(&self) -> Option<u64>
Return the number of times a cached value was successfully retrieved
sourcefn cache_misses(&self) -> Option<u64>
fn cache_misses(&self) -> Option<u64>
Return the number of times a cached value was unable to be retrieved
sourcefn cache_reset_metrics(&mut self)
fn cache_reset_metrics(&mut self)
Reset misses/hits counters
sourcefn cache_capacity(&self) -> Option<usize>
fn cache_capacity(&self) -> Option<usize>
Return the cache capacity
sourcefn cache_lifespan(&self) -> Option<u64>
fn cache_lifespan(&self) -> Option<u64>
Return the lifespan of cached values (time to eviction)
sourcefn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64>
fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64>
Set the lifespan of cached values, returns the old value
Auto Trait Implementations
impl<K, V> RefUnwindSafe for ExpiringValueCache<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for ExpiringValueCache<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for ExpiringValueCache<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for ExpiringValueCache<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for ExpiringValueCache<K, V> where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more