pub struct BoundedMap<K, V> { /* private fields */ }Expand description
Capacity-bounded, optionally TTL-swept map for caches and rate-limit tables.
Eviction order is oldest-insert (approximate LRU: a re-insert of an existing
key moves it to newest; get refreshes the idle timestamp but does not
reorder). insert returns any (key, value) evicted for capacity so the
caller can persist-before-drop. capacity == 0 disables the cache,
mirroring Ring.
Implementations§
Source§impl<K: Eq + Hash + Clone, V> BoundedMap<K, V>
impl<K: Eq + Hash + Clone, V> BoundedMap<K, V>
pub fn new(capacity: usize, idle_ttl_secs: u64, gauge: SizeGauge) -> Self
pub fn insert(&mut self, key: K, value: V, now_secs: u64) -> Option<(K, V)>
pub fn get(&mut self, key: &K, now_secs: u64) -> Option<&V>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
Auto Trait Implementations§
impl<K, V> Freeze for BoundedMap<K, V>
impl<K, V> RefUnwindSafe for BoundedMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for BoundedMap<K, V>
impl<K, V> Sync for BoundedMap<K, V>
impl<K, V> Unpin for BoundedMap<K, V>
impl<K, V> UnsafeUnpin for BoundedMap<K, V>
impl<K, V> UnwindSafe for BoundedMap<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