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
impl CoreCacheMetrics
Sourcepub fn new(max_cache_size_bytes: u64) -> Self
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
Sourcepub fn record_hit(&mut self, object_size: u64)
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)
Sourcepub fn record_miss(&mut self, object_size: u64)
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)
Sourcepub fn record_eviction(&mut self, evicted_size: u64)
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)
Sourcepub fn record_insertion(&mut self, object_size: u64)
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)
Sourcepub fn record_size_change(&mut self, old_size: u64, new_size: u64)
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)
Sourcepub fn hit_rate(&self) -> f64
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
Sourcepub fn miss_rate(&self) -> f64
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
Sourcepub fn byte_hit_rate(&self) -> f64
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
Sourcepub fn cache_utilization(&self) -> f64
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
Sourcepub fn to_btreemap(&self) -> BTreeMap<String, f64>
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
impl Clone for CoreCacheMetrics
Source§fn clone(&self) -> CoreCacheMetrics
fn clone(&self) -> CoreCacheMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more