pub struct TimedSizedCache<K, V> { /* private fields */ }
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§
source§impl<K: Hash + Eq + Clone, V> TimedSizedCache<K, V>
impl<K: Hash + Eq + Clone, V> TimedSizedCache<K, V>
sourcepub fn with_size_and_lifespan(
size: usize,
seconds: u64,
) -> TimedSizedCache<K, V>
pub fn with_size_and_lifespan( size: usize, seconds: u64, ) -> TimedSizedCache<K, V>
Creates a new SizedCache
with a given size limit and pre-allocated backing data
sourcepub 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 retrieving
§Panics
Will panic if size is 0
sourcepub fn try_with_size_and_lifespan(
size: usize,
seconds: u64,
) -> Result<TimedSizedCache<K, V>>
pub fn try_with_size_and_lifespan( size: usize, seconds: u64, ) -> Result<TimedSizedCache<K, V>>
Creates a new TimedSizedCache
with a specified lifespan and a given size limit and pre-allocated backing data
§Errors
Will return a std::io::Error
, depending on the error
sourcepub fn key_order(&self) -> impl Iterator<Item = &K>
pub fn key_order(&self) -> impl Iterator<Item = &K>
Return an iterator of keys in the current order from most to least recently used. Items passed their expiration seconds will be excluded.
sourcepub fn value_order(&self) -> impl Iterator<Item = &(Instant, V)>
pub fn value_order(&self) -> impl Iterator<Item = &(Instant, V)>
Return an iterator of timestamped values in the current order from most to least recently used. Items passed their expiration seconds will be excluded.
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
sourcepub fn get_store(&self) -> &SizedCache<K, (Instant, V)>
pub fn get_store(&self) -> &SizedCache<K, (Instant, V)>
Returns a reference to the cache’s store
Trait Implementations§
source§impl<K: Hash + Eq + Clone, V> Cached<K, V> for TimedSizedCache<K, V>
impl<K: Hash + Eq + Clone, V> Cached<K, V> for TimedSizedCache<K, V>
source§fn cache_get<Q>(&mut self, key: &Q) -> Option<&V>
fn cache_get<Q>(&mut self, key: &Q) -> Option<&V>
source§fn cache_get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
fn cache_get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
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
source§fn cache_try_get_or_set_with<F: FnOnce() -> Result<V, E>, E>(
&mut self,
key: K,
f: F,
) -> Result<&mut V, E>
fn cache_try_get_or_set_with<F: FnOnce() -> Result<V, E>, E>( &mut self, key: K, f: F, ) -> Result<&mut V, E>
source§fn cache_set(&mut self, key: K, val: V) -> Option<V>
fn cache_set(&mut self, key: K, val: V) -> Option<V>
source§fn cache_clear(&mut self)
fn cache_clear(&mut self)
source§fn cache_reset(&mut self)
fn cache_reset(&mut self)
source§fn cache_reset_metrics(&mut self)
fn cache_reset_metrics(&mut self)
source§fn cache_size(&self) -> usize
fn cache_size(&self) -> usize
source§fn cache_hits(&self) -> Option<u64>
fn cache_hits(&self) -> Option<u64>
source§fn cache_misses(&self) -> Option<u64>
fn cache_misses(&self) -> Option<u64>
source§fn cache_capacity(&self) -> Option<usize>
fn cache_capacity(&self) -> Option<usize>
source§fn cache_lifespan(&self) -> Option<u64>
fn cache_lifespan(&self) -> Option<u64>
source§impl<K: Clone, V: Clone> Clone for TimedSizedCache<K, V>
impl<K: Clone, V: Clone> Clone for TimedSizedCache<K, V>
source§fn clone(&self) -> TimedSizedCache<K, V>
fn clone(&self) -> TimedSizedCache<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<K: Hash + Eq + Clone, V: Clone> CloneCached<K, V> for TimedSizedCache<K, V>
impl<K: Hash + Eq + Clone, V: Clone> CloneCached<K, V> for TimedSizedCache<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for TimedSizedCache<K, V>
impl<K, V> RefUnwindSafe for TimedSizedCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for TimedSizedCache<K, V>
impl<K, V> Sync for TimedSizedCache<K, V>
impl<K, V> Unpin for TimedSizedCache<K, V>
impl<K, V> UnwindSafe for TimedSizedCache<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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)