pub struct MultiLevelCache<K, V>{ /* private fields */ }Expand description
Scan-resistant cache backed by Moka’s TinyLFU
TinyLFU tracks frequency of both hits and misses, rejecting infrequent “scan” accesses that would pollute a pure LRU cache.
Implementations§
Source§impl<K, V> MultiLevelCache<K, V>
impl<K, V> MultiLevelCache<K, V>
Sourcepub fn new(l1_size: usize, l2_size: usize) -> Self
pub fn new(l1_size: usize, l2_size: usize) -> Self
Build a scan-resistant cache with specified capacity
The l1_size and l2_size parameters are combined for total capacity.
Moka’s TinyLFU internally manages hot/cold separation.
Sourcepub fn get(&self, key: &K) -> Option<V>
pub fn get(&self, key: &K) -> Option<V>
Look up a cached value
TinyLFU admission policy means frequently-accessed keys stay cached while scan-like one-time accesses are rejected.
Sourcepub fn insert(&self, key: K, value: V)
pub fn insert(&self, key: K, value: V)
Store a value in the cache
Note: TinyLFU may reject this entry if the key hasn’t been seen frequently enough. This is intentional for scan resistance.
Sourcepub fn avg_access_time(&self) -> Duration
pub fn avg_access_time(&self) -> Duration
Average access time for cache hits
Sourcepub fn metrics(&self) -> CacheMetrics
pub fn metrics(&self) -> CacheMetrics
Full performance snapshot
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for MultiLevelCache<K, V>
impl<K, V> !RefUnwindSafe for MultiLevelCache<K, V>
impl<K, V> Send for MultiLevelCache<K, V>
impl<K, V> Sync for MultiLevelCache<K, V>
impl<K, V> Unpin for MultiLevelCache<K, V>
impl<K, V> UnsafeUnpin for MultiLevelCache<K, V>
impl<K, V> !UnwindSafe for MultiLevelCache<K, V>
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