Struct CoreCacheMetrics

Source
pub struct CoreCacheMetrics {
    pub requests: u64,
    pub cache_hits: u64,
    pub total_bytes_requested: u64,
    pub bytes_served_from_cache: u64,
    pub bytes_written_to_cache: u64,
    pub evictions: u64,
    pub cache_size_bytes: u64,
    pub max_cache_size_bytes: u64,
}
Expand description

Common metrics tracked by all cache algorithms

Fields§

§requests: u64

Total number of requests (gets) made to the cache

§cache_hits: u64

Number of requests that resulted in cache hits

§total_bytes_requested: u64

Total bytes of data requested from the cache (hits + misses)

§bytes_served_from_cache: u64

Total bytes served directly from cache (cache hits only)

§bytes_written_to_cache: u64

Total bytes written/stored into the cache

§evictions: u64

Number of items evicted from the cache due to capacity constraints

§cache_size_bytes: u64

Current size of data stored in the cache (in bytes)

§max_cache_size_bytes: u64

Maximum allowed cache size (in bytes) - the capacity limit

Implementations§

Source§

impl CoreCacheMetrics

Source

pub fn new(max_cache_size_bytes: u64) -> Self

Creates a new CoreCacheMetrics instance with the specified maximum cache size

§Arguments
  • max_cache_size_bytes - The maximum allowed cache size in bytes
Source

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

Records a cache hit - when requested data was found in the cache

This increments total requests, cache hits, total bytes requested, and bytes served from cache.

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

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

Records a cache miss - when requested data was not found in the cache

This increments total requests and total bytes requested. Cache misses are calculated as (requests - cache_hits).

§Arguments
  • object_size - Size of the object that was requested but not in cache (in bytes)
Source

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

Records an eviction - when an item is removed from cache due to capacity constraints

This increments the eviction counter and decreases the current cache size.

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

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

Records an insertion - when new data is written to the cache

This increases the current cache size and tracks bytes written to cache.

§Arguments
  • object_size - Size of the object being inserted (in bytes)
Source

pub fn record_size_change(&mut self, old_size: u64, new_size: u64)

Records a size change for an existing cache entry

This adjusts the current cache size when an existing entry’s size changes.

§Arguments
  • old_size - Previous size of the object (in bytes)
  • new_size - New size of the object (in bytes)
Source

pub fn hit_rate(&self) -> f64

Calculates the cache hit rate as a percentage

§Returns

A value between 0.0 and 1.0 representing the hit rate, or 0.0 if no requests have been made

Source

pub fn miss_rate(&self) -> f64

Calculates the cache miss rate as a percentage

§Returns

A value between 0.0 and 1.0 representing the miss rate, or 0.0 if no requests have been made

Source

pub fn byte_hit_rate(&self) -> f64

Calculates the byte hit rate - ratio of bytes served from cache vs total bytes requested

This metric shows how much of the requested data volume was served from cache.

§Returns

A value between 0.0 and 1.0 representing the byte hit rate, or 0.0 if no bytes have been requested

Source

pub fn cache_utilization(&self) -> f64

Calculates cache utilization - how full the cache is relative to its maximum capacity

§Returns

A value between 0.0 and 1.0 representing cache utilization, or 0.0 if max capacity is 0

Source

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

Convert core metrics to BTreeMap for reporting

Uses BTreeMap to ensure deterministic, consistent ordering of metrics which is critical for reproducible testing and comparison results.

§Returns

A BTreeMap containing all core metrics with consistent key ordering

Trait Implementations§

Source§

impl Clone for CoreCacheMetrics

Source§

fn clone(&self) -> CoreCacheMetrics

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 CoreCacheMetrics

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CoreCacheMetrics

Source§

fn default() -> CoreCacheMetrics

Returns the “default value” for a type. 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.