pub struct TtlCache<K: Clone + Eq + Hash, V: Clone> { /* private fields */ }Expand description
A simple TTL-based cache using a step counter as a clock.
Each entry has a ttl expressed in “steps”. The cache is checked on every
get; stale entries are lazily removed.
Implementations§
Source§impl<K: Clone + Eq + Hash, V: Clone> TtlCache<K, V>
impl<K: Clone + Eq + Hash, V: Clone> TtlCache<K, V>
Sourcepub fn insert_with_ttl(&mut self, key: K, value: V, ttl: u64)
pub fn insert_with_ttl(&mut self, key: K, value: V, ttl: u64)
Insert an entry with a custom TTL.
Sourcepub fn purge_expired(&mut self)
pub fn purge_expired(&mut self)
Remove expired entries.
Sourcepub fn current_step(&self) -> u64
pub fn current_step(&self) -> u64
Current step counter.
Auto Trait Implementations§
impl<K, V> Freeze for TtlCache<K, V>
impl<K, V> RefUnwindSafe for TtlCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for TtlCache<K, V>
impl<K, V> Sync for TtlCache<K, V>
impl<K, V> Unpin for TtlCache<K, V>
impl<K, V> UnsafeUnpin for TtlCache<K, V>
impl<K, V> UnwindSafe for TtlCache<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