Struct SlruCacheMetrics

Source
pub struct SlruCacheMetrics {
    pub core: CoreCacheMetrics,
    pub probationary_size: u64,
    pub protected_size: u64,
    pub protected_max_size: u64,
    pub total_promotions: u64,
    pub total_demotions: u64,
    pub probationary_hits: u64,
    pub protected_hits: u64,
    pub probationary_evictions: u64,
    pub protected_evictions: u64,
}
Expand description

SLRU-specific metrics (extends CoreCacheMetrics)

This struct contains metrics specific to the SLRU (Segmented LRU) cache algorithm. SLRU divides the cache into probationary and protected segments, so these metrics focus on segment utilization and promotion/demotion patterns.

Fields§

§core: CoreCacheMetrics

Core metrics common to all cache algorithms

§probationary_size: u64

Number of items currently in the probationary segment

§protected_size: u64

Number of items currently in the protected segment

§protected_max_size: u64

Maximum allowed size for the protected segment

§total_promotions: u64

Total number of promotions from probationary to protected segment

§total_demotions: u64

Total number of demotions from protected to probationary segment

§probationary_hits: u64

Number of cache hits in the probationary segment

§protected_hits: u64

Number of cache hits in the protected segment

§probationary_evictions: u64

Number of evictions from the probationary segment

§protected_evictions: u64

Number of evictions from the protected segment

Implementations§

Source§

impl SlruCacheMetrics

Source

pub fn new(max_cache_size_bytes: u64, protected_max_size: u64) -> Self

Creates a new SlruCacheMetrics instance with the specified parameters

§Arguments
  • max_cache_size_bytes - The maximum allowed cache size in bytes
  • protected_max_size - The maximum number of items in protected segment
Source

pub fn record_promotion(&mut self)

Records a promotion from probationary to protected segment

Source

pub fn record_demotion(&mut self)

Records a demotion from protected to probationary segment

Source

pub fn record_probationary_hit(&mut self, object_size: u64)

Records a cache hit in the probationary segment

§Arguments
  • object_size - Size of the object that was served from cache (in bytes)
Source

pub fn record_protected_hit(&mut self, object_size: u64)

Records a cache hit in the protected segment

§Arguments
  • object_size - Size of the object that was served from cache (in bytes)
Source

pub fn record_probationary_eviction(&mut self, evicted_size: u64)

Records an eviction from the probationary segment

§Arguments
  • evicted_size - Size of the evicted object (in bytes)
Source

pub fn record_protected_eviction(&mut self, evicted_size: u64)

Records an eviction from the protected segment

§Arguments
  • evicted_size - Size of the evicted object (in bytes)
Source

pub fn update_segment_sizes( &mut self, probationary_size: u64, protected_size: u64, )

Updates the segment sizes

§Arguments
  • probationary_size - Current number of items in probationary segment
  • protected_size - Current number of items in protected segment
Source

pub fn protection_ratio(&self) -> f64

Calculates the protection ratio (protected hits / total hits)

§Returns

Ratio of hits in protected segment vs total hits, or 0.0 if no hits

Source

pub fn promotion_efficiency(&self) -> f64

Calculates the promotion efficiency (promotions / probationary hits)

§Returns

How often probationary hits lead to promotions, or 0.0 if no probationary hits

Source

pub fn protected_utilization(&self) -> f64

Calculates protected segment utilization

§Returns

Ratio of current protected size to maximum protected size

Source

pub fn to_btreemap(&self) -> BTreeMap<String, f64>

Converts SLRU metrics to a BTreeMap for reporting

This method returns all metrics relevant to the SLRU cache algorithm, including both core metrics and SLRU-specific segment metrics.

Uses BTreeMap to ensure consistent, deterministic ordering of metrics.

§Returns

A BTreeMap containing all SLRU cache metrics as key-value pairs

Trait Implementations§

Source§

impl CacheMetrics for SlruCacheMetrics

Source§

fn metrics(&self) -> BTreeMap<String, f64>

Returns all SLRU cache metrics as key-value pairs in deterministic order

§Returns

A BTreeMap containing all metrics tracked by this SLRU cache instance

Source§

fn algorithm_name(&self) -> &'static str

Returns the algorithm name for this cache implementation

§Returns

“SLRU” - identifying this as a Segmented Least Recently Used cache

Source§

impl Clone for SlruCacheMetrics

Source§

fn clone(&self) -> SlruCacheMetrics

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SlruCacheMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.