Struct cached::stores::TimedCache
source · pub struct TimedCache<K, V> { /* private fields */ }
Expand description
Cache store bound by time
Values are timestamped when inserted and are evicted if expired at time of retrieval.
Note: This cache is in-memory only
Implementations§
source§impl<K: Hash + Eq, V> TimedCache<K, V>
impl<K: Hash + Eq, V> TimedCache<K, V>
sourcepub fn with_lifespan(seconds: u64) -> TimedCache<K, V>
pub fn with_lifespan(seconds: u64) -> TimedCache<K, V>
Creates a new TimedCache
with a specified lifespan
sourcepub fn with_lifespan_and_capacity(seconds: u64, size: usize) -> TimedCache<K, V>
pub fn with_lifespan_and_capacity(seconds: u64, size: usize) -> TimedCache<K, V>
Creates a new TimedCache
with a specified lifespan and
cache-store with the specified pre-allocated capacity
sourcepub fn with_lifespan_and_refresh(
seconds: u64,
refresh: bool
) -> TimedCache<K, V>
pub fn with_lifespan_and_refresh( seconds: u64, refresh: bool ) -> TimedCache<K, V>
Creates a new TimedCache
with a specified lifespan which
refreshes the ttl when the entry is retrieved
sourcepub fn set_refresh(&mut self, refresh: bool)
pub fn set_refresh(&mut self, refresh: bool)
Sets if the lifetime is refreshed when the value is retrieved
Trait Implementations§
source§impl<K: Hash + Eq, V> Cached<K, V> for TimedCache<K, V>
impl<K: Hash + Eq, V> Cached<K, V> for TimedCache<K, V>
source§fn cache_get<Q>(&mut self, key: &Q) -> Option<&V>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
fn cache_get<Q>(&mut self, key: &Q) -> Option<&V>where K: Borrow<Q>, Q: Hash + Eq + ?Sized,
Attempt to retrieve a cached value Read more
source§fn cache_get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
fn cache_get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where K: Borrow<Q>, Q: Hash + Eq + ?Sized,
Attempt to retrieve a cached value with mutable access Read more
source§fn cache_get_or_set_with<F: FnOnce() -> V>(&mut self, key: K, f: F) -> &mut V
fn cache_get_or_set_with<F: FnOnce() -> V>(&mut self, key: K, f: F) -> &mut V
Get or insert a key, value pair
source§fn cache_set(&mut self, key: K, val: V) -> Option<V>
fn cache_set(&mut self, key: K, val: V) -> Option<V>
Insert a key, value pair and return the previous value
source§fn cache_remove<Q>(&mut self, k: &Q) -> Option<V>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
fn cache_remove<Q>(&mut self, k: &Q) -> Option<V>where K: Borrow<Q>, Q: Hash + Eq + ?Sized,
Remove a cached value Read more
source§fn cache_clear(&mut self)
fn cache_clear(&mut self)
Remove all cached values. Keeps the allocated memory for reuse.
source§fn cache_reset_metrics(&mut self)
fn cache_reset_metrics(&mut self)
Reset misses/hits counters
source§fn cache_reset(&mut self)
fn cache_reset(&mut self)
Remove all cached values. Free memory and return to initial state
source§fn cache_size(&self) -> usize
fn cache_size(&self) -> usize
Return the current cache size (number of elements)
source§fn cache_hits(&self) -> Option<u64>
fn cache_hits(&self) -> Option<u64>
Return the number of times a cached value was successfully retrieved
source§fn cache_misses(&self) -> Option<u64>
fn cache_misses(&self) -> Option<u64>
Return the number of times a cached value was unable to be retrieved
source§fn cache_lifespan(&self) -> Option<u64>
fn cache_lifespan(&self) -> Option<u64>
Return the lifespan of cached values (time to eviction)
source§fn 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
source§fn cache_capacity(&self) -> Option<usize>
fn cache_capacity(&self) -> Option<usize>
Return the cache capacity
source§impl<K, V> CachedAsync<K, V> for TimedCache<K, V>where
K: Hash + Eq + Clone + Send,
impl<K, V> CachedAsync<K, V> for TimedCache<K, V>where K: Hash + Eq + Clone + Send,
fn get_or_set_with<'life0, 'async_trait, F, Fut>( &'life0 mut self, k: K, f: F ) -> Pin<Box<dyn Future<Output = &mut V> + Send + 'async_trait>>where V: Send, F: FnOnce() -> Fut + Send + 'async_trait, Fut: Future<Output = V> + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,
fn try_get_or_set_with<'life0, 'async_trait, F, Fut, E>( &'life0 mut self, k: K, f: F ) -> Pin<Box<dyn Future<Output = Result<&mut V, E>> + Send + 'async_trait>>where V: Send, F: FnOnce() -> Fut + Send + 'async_trait, Fut: Future<Output = Result<V, E>> + Send + 'async_trait, E: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,
Auto Trait Implementations§
impl<K, V> RefUnwindSafe for TimedCache<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,
impl<K, V> Send for TimedCache<K, V>where K: Send, V: Send,
impl<K, V> Sync for TimedCache<K, V>where K: Sync, V: Sync,
impl<K, V> Unpin for TimedCache<K, V>where K: Unpin, V: Unpin,
impl<K, V> UnwindSafe for TimedCache<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