Struct cached::TimedSizedCache [−][src]
pub struct TimedSizedCache<K, V> { /* fields omitted */ }
Expand description
Timed LRU Cache
Stores a limited number of values, evicting expired and least-used entries. Time expiration is determined based on entry insertion time.. The TTL of an entry is not updated when retrieved.
Note: This cache is in-memory only
Implementations
Creates a new SizedCache
with a given size limit and pre-allocated backing data
pub fn with_size_and_lifespan_and_refresh(
size: usize,
seconds: u64,
refresh: bool
) -> TimedSizedCache<K, V>
pub fn with_size_and_lifespan_and_refresh(
size: usize,
seconds: u64,
refresh: bool
) -> TimedSizedCache<K, V>
Creates a new SizedCache
with a given size limit and pre-allocated backing data.
Also set if the ttl should be refreshed on retriving
Return an iterator of keys in the current order from most to least recently used. Items passed their expiration seconds will be excluded.
Return an iterator of timestamped values in the current order from most to least recently used. Items passed their expiration seconds will be excluded.
Sets if the lifetime is refreshed when the value is retrived
Trait Implementations
Attempt to retrieve a cached value with mutable access
Get or insert a key, value pair
Insert a key, value pair and return the previous value
Remove a cached value
Remove all cached values. Keeps the allocated memory for reuse.
Remove all cached values. Free memory and return to initial state
Reset misses/hits counters
Return the current cache size (number of elements)
Return the number of times a cached value was successfully retrieved
Return the number of times a cached value was unable to be retrieved
Return the cache capacity
Return the lifespan of cached values (time to eviction)
Set the lifespan of cached values, returns the old value
fn get_or_set_with<'life0, 'async_trait, F, Fut>(
&'life0 mut self,
key: K,
f: F
) -> Pin<Box<dyn Future<Output = &mut V> + Send + 'async_trait>> where
V: Send,
F: FnOnce() -> Fut + Send,
Fut: Future<Output = V> + Send,
F: 'async_trait,
Fut: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn try_get_or_set_with<'life0, 'async_trait, F, Fut, E>(
&'life0 mut self,
key: K,
f: F
) -> Pin<Box<dyn Future<Output = Result<&mut V, E>> + Send + 'async_trait>> where
V: Send,
F: FnOnce() -> Fut + Send,
Fut: Future<Output = Result<V, E>> + Send,
F: 'async_trait,
Fut: 'async_trait,
E: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Auto Trait Implementations
impl<K, V> RefUnwindSafe for TimedSizedCache<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for TimedSizedCache<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for TimedSizedCache<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for TimedSizedCache<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for TimedSizedCache<K, V> where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more