pub struct FifoCacheMap<K, V, const N: usize>{ /* private fields */ }Expand description
A bounded cache that maintains key-value pairs with O(1) lookups.
Uses an ArrayDeque for FIFO ordering and an AHashMap for fast key-value access.
When capacity is exceeded, the oldest entry is automatically evicted.
§Examples
use nautilus_common::cache::fifo::FifoCacheMap;
let mut cache: FifoCacheMap<u32, String, 3> = FifoCacheMap::new();
cache.insert(1, "one".to_string());
cache.insert(2, "two".to_string());
cache.insert(3, "three".to_string());
assert_eq!(cache.get(&1), Some(&"one".to_string()));
// Adding beyond capacity evicts the oldest
cache.insert(4, "four".to_string());
assert_eq!(cache.get(&1), None);
assert_eq!(cache.get(&4), Some(&"four".to_string()));Zero capacity is a compile-time error:
ⓘ
use nautilus_common::cache::fifo::FifoCacheMap;
// This fails to compile: capacity must be > 0
let cache: FifoCacheMap<u32, String, 0> = FifoCacheMap::new();Implementations§
Source§impl<K, V, const N: usize> FifoCacheMap<K, V, N>
impl<K, V, const N: usize> FifoCacheMap<K, V, N>
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns whether the cache contains the given key (O(1) lookup).
Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value for the given key (O(1) lookup).
Sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value for the given key (O(1) lookup).
Sourcepub fn insert(&mut self, key: K, value: V)
pub fn insert(&mut self, key: K, value: V)
Inserts a key-value pair into the cache.
If the key already exists, the value is updated (no eviction occurs). If the cache is at capacity and the key is new, the oldest entry is evicted.
Trait Implementations§
Auto Trait Implementations§
impl<K, V, const N: usize> Freeze for FifoCacheMap<K, V, N>where
K: Freeze,
impl<K, V, const N: usize> RefUnwindSafe for FifoCacheMap<K, V, N>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, const N: usize> Send for FifoCacheMap<K, V, N>
impl<K, V, const N: usize> Sync for FifoCacheMap<K, V, N>
impl<K, V, const N: usize> Unpin for FifoCacheMap<K, V, N>
impl<K, V, const N: usize> UnsafeUnpin for FifoCacheMap<K, V, N>where
K: UnsafeUnpin,
impl<K, V, const N: usize> UnwindSafe for FifoCacheMap<K, V, N>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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more