Struct cached::stores::TimedSizedCache
source · 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