pub struct LfuCacheMetrics {
pub core: CoreCacheMetrics,
pub min_frequency: u64,
pub max_frequency: u64,
pub total_frequency_increments: u64,
pub active_frequency_levels: u64,
}
Expand description
LFU-specific metrics (extends CoreCacheMetrics)
This struct contains metrics specific to the LFU (Least Frequently Used) cache algorithm. LFU tracks frequency of access for each item, so these metrics focus on frequency distribution and access patterns.
Fields§
§core: CoreCacheMetrics
Core metrics common to all cache algorithms
min_frequency: u64
Current minimum frequency in the cache
max_frequency: u64
Current maximum frequency in the cache
total_frequency_increments: u64
Total number of frequency increments (every cache hit increases frequency)
active_frequency_levels: u64
Number of unique frequency levels currently in use
Implementations§
Source§impl LfuCacheMetrics
impl LfuCacheMetrics
Sourcepub fn new(max_cache_size_bytes: u64) -> Self
pub fn new(max_cache_size_bytes: u64) -> Self
Creates a new LfuCacheMetrics instance with the specified maximum cache size
§Arguments
max_cache_size_bytes
- The maximum allowed cache size in bytes
Sourcepub fn record_frequency_increment(
&mut self,
_old_frequency: usize,
new_frequency: usize,
)
pub fn record_frequency_increment( &mut self, _old_frequency: usize, new_frequency: usize, )
Records a frequency increment (when an item is accessed and its frequency increases)
§Arguments
old_frequency
- The previous frequency valuenew_frequency
- The new frequency value for the accessed item
Sourcepub fn record_frequency_hit(&mut self, object_size: u64, frequency: usize)
pub fn record_frequency_hit(&mut self, object_size: u64, frequency: usize)
Records a cache hit with frequency information
§Arguments
object_size
- Size of the object that was served from cache (in bytes)frequency
- Current frequency of the accessed item
Sourcepub fn update_frequency_levels<T>(
&mut self,
frequency_lists: &BTreeMap<usize, T>,
)
pub fn update_frequency_levels<T>( &mut self, frequency_lists: &BTreeMap<usize, T>, )
Updates the frequency levels based on current frequency lists
§Arguments
frequency_lists
- Map of frequency to list of items at that frequency
Sourcepub fn record_miss(&mut self, object_size: u64)
pub fn record_miss(&mut self, object_size: u64)
Records a cache miss for LFU metrics
§Arguments
object_size
- Size of the object that was requested (in bytes)
Sourcepub fn update_active_frequency_levels(&mut self, levels: u64)
pub fn update_active_frequency_levels(&mut self, levels: u64)
Updates the count of active frequency levels
§Arguments
levels
- The number of different frequency levels currently in use
Sourcepub fn average_frequency(&self) -> f64
pub fn average_frequency(&self) -> f64
Calculates the average frequency of accesses
§Returns
Average frequency per item access, or 0.0 if no hits have occurred
Sourcepub fn frequency_range(&self) -> u64
pub fn frequency_range(&self) -> u64
Sourcepub fn to_btreemap(&self) -> BTreeMap<String, f64>
pub fn to_btreemap(&self) -> BTreeMap<String, f64>
Converts LFU metrics to a BTreeMap for reporting
This method returns all metrics relevant to the LFU cache algorithm, including both core metrics and LFU-specific frequency metrics.
Uses BTreeMap to ensure consistent, deterministic ordering of metrics.
§Returns
A BTreeMap containing all LFU cache metrics as key-value pairs
Trait Implementations§
Source§impl CacheMetrics for LfuCacheMetrics
impl CacheMetrics for LfuCacheMetrics
Source§fn metrics(&self) -> BTreeMap<String, f64>
fn metrics(&self) -> BTreeMap<String, f64>
Returns all LFU cache metrics as key-value pairs in deterministic order
§Returns
A BTreeMap containing all metrics tracked by this LFU cache instance
Source§fn algorithm_name(&self) -> &'static str
fn algorithm_name(&self) -> &'static str
Returns the algorithm name for this cache implementation
§Returns
“LFU” - identifying this as a Least Frequently Used cache
Source§impl Clone for LfuCacheMetrics
impl Clone for LfuCacheMetrics
Source§fn clone(&self) -> LfuCacheMetrics
fn clone(&self) -> LfuCacheMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more