pub struct TwoQueueCache<K: Eq + Hash + Clone, V> { /* private fields */ }Expand description
A 2Q cache with configurable total capacity and A1in/A1out sizing.
§Type parameters
K— key type (must beEq + Hash + Clone).V— value type.
Implementations§
Source§impl<K: Eq + Hash + Clone, V> TwoQueueCache<K, V>
impl<K: Eq + Hash + Clone, V> TwoQueueCache<K, V>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new 2Q cache with the given capacity.
A1in is sized to ~25% of capacity and A1out to ~50%.
Sourcepub fn with_queue_sizes(
capacity: usize,
a1in_capacity: usize,
a1out_capacity: usize,
) -> Self
pub fn with_queue_sizes( capacity: usize, a1in_capacity: usize, a1out_capacity: usize, ) -> Self
Create a 2Q cache with explicit A1in and A1out sizing.
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Look up key. On a hit in Am, promote to MRU. On a hit in A1in,
the entry stays in place (FIFO semantics).
Sourcepub fn insert(&mut self, key: K, value: V)
pub fn insert(&mut self, key: K, value: V)
Insert (key, value) into the cache.
- If
keyis already in Am or A1in, its value is updated. - If
keyis in A1out (ghost hit), it is admitted to Am. - Otherwise it enters A1in.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove key from the cache entirely (including ghost list).
Sourcepub fn contains(&self, key: &K) -> bool
pub fn contains(&self, key: &K) -> bool
Returns true if the cache contains key (not counting ghosts).
Sourcepub fn stats(&self) -> TwoQueueStats
pub fn stats(&self) -> TwoQueueStats
Return a statistics snapshot.
Sourcepub fn peek(&self, key: &K) -> Option<&V>
pub fn peek(&self, key: &K) -> Option<&V>
Peek at key without updating access metadata or LRU order.
Auto Trait Implementations§
impl<K, V> Freeze for TwoQueueCache<K, V>
impl<K, V> RefUnwindSafe for TwoQueueCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for TwoQueueCache<K, V>
impl<K, V> Sync for TwoQueueCache<K, V>
impl<K, V> Unpin for TwoQueueCache<K, V>
impl<K, V> UnsafeUnpin for TwoQueueCache<K, V>
impl<K, V> UnwindSafe for TwoQueueCache<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