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
impl SlruCacheMetrics
Sourcepub fn new(max_cache_size_bytes: u64, protected_max_size: u64) -> Self
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 bytesprotected_max_size
- The maximum number of items in protected segment
Sourcepub fn record_promotion(&mut self)
pub fn record_promotion(&mut self)
Records a promotion from probationary to protected segment
Sourcepub fn record_demotion(&mut self)
pub fn record_demotion(&mut self)
Records a demotion from protected to probationary segment
Sourcepub fn record_probationary_hit(&mut self, object_size: u64)
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)
Sourcepub fn record_protected_hit(&mut self, object_size: u64)
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)
Sourcepub fn record_probationary_eviction(&mut self, evicted_size: u64)
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)
Sourcepub fn record_protected_eviction(&mut self, evicted_size: u64)
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)
Sourcepub fn update_segment_sizes(
&mut self,
probationary_size: u64,
protected_size: u64,
)
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 segmentprotected_size
- Current number of items in protected segment
Sourcepub fn protection_ratio(&self) -> f64
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
Sourcepub fn promotion_efficiency(&self) -> f64
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
Sourcepub fn protected_utilization(&self) -> f64
pub fn protected_utilization(&self) -> f64
Calculates protected segment utilization
§Returns
Ratio of current protected size to maximum protected size
Sourcepub fn to_btreemap(&self) -> BTreeMap<String, f64>
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
impl CacheMetrics for SlruCacheMetrics
Source§fn metrics(&self) -> BTreeMap<String, f64>
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
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
impl Clone for SlruCacheMetrics
Source§fn clone(&self) -> SlruCacheMetrics
fn clone(&self) -> SlruCacheMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more