pub struct TimeBoundCache<K, V> { /* private fields */ }
Expand description
A hash map where entries expire after a time
Implementations§
Source§impl<K: Hash + Eq + Clone, V> TimeBoundCache<K, V>
impl<K: Hash + Eq + Clone, V> TimeBoundCache<K, V>
Sourcepub fn insert(&mut self, key: K, value: V, expires: Instant)
pub fn insert(&mut self, key: K, value: V, expires: Instant)
Insert an item into the cache, marked with an expiration time.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true
if the map contains a value for the specified key.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V, &Instant)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V, &Instant)>
Iterate over all items in the cache.
Sourcepub fn expire_until(&mut self, instant: Instant) -> usize
pub fn expire_until(&mut self, instant: Instant) -> usize
Remove all entries with an expiry instant lower or equal to instant
.
Returns the number of items that were removed.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for TimeBoundCache<K, V>
impl<K, V> RefUnwindSafe for TimeBoundCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for TimeBoundCache<K, V>
impl<K, V> Sync for TimeBoundCache<K, V>
impl<K, V> Unpin for TimeBoundCache<K, V>
impl<K, V> UnwindSafe for TimeBoundCache<K, V>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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