Skip to main content

MultiLevelCache

Struct MultiLevelCache 

Source
pub struct MultiLevelCache<K: Clone + Eq + Hash, V: Clone> { /* private fields */ }
Expand description

A two-level cache hierarchy.

L1 is a small, fast LRU cache. L2 is a larger LRU cache. On a miss in L1, L2 is checked and the result is promoted to L1.

Implementations§

Source§

impl<K: Clone + Eq + Hash, V: Clone> MultiLevelCache<K, V>

Source

pub fn new(l1_cap: usize, l2_cap: usize) -> Self

Create a two-level cache.

Source

pub fn get(&mut self, key: &K) -> Option<V>

Get a value, checking L1 first, then L2.

Source

pub fn insert(&mut self, key: K, value: V)

Insert into both L1 and L2.

Source

pub fn insert_l2_only(&mut self, key: K, value: V)

Insert only into L2 (for pre-warming the L2 cache).

Source

pub fn clear_l1(&mut self)

Clear L1 only.

Source

pub fn clear_all(&mut self)

Clear both levels.

Source

pub fn l1_hits(&self) -> u64

L1 hit count.

Source

pub fn l2_hits(&self) -> u64

L2 hit count.

Source

pub fn misses(&self) -> u64

Miss count.

Source

pub fn total_requests(&self) -> u64

Total requests served.

Source

pub fn hit_rate(&self) -> f64

Overall hit rate.

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>
where K: Send, V: Send,

§

impl<K, V> Sync for MultiLevelCache<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for MultiLevelCache<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnsafeUnpin for MultiLevelCache<K, V>

§

impl<K, V> UnwindSafe for MultiLevelCache<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.