pub struct GdsfCacheMetrics {
pub core: CoreCacheMetrics,
pub global_age: f64,
pub total_aging_events: u64,
pub min_priority: f64,
pub max_priority: f64,
pub total_frequency: u64,
pub total_item_size_processed: u64,
pub small_items_cached: u64,
pub large_items_cached: u64,
pub size_based_evictions: u64,
pub total_frequency_size_ratio: f64,
}
Expand description
GDSF-specific metrics (extends CoreCacheMetrics)
This struct contains metrics specific to the GDSF (Greedy Dual-Size Frequency) cache algorithm. GDSF combines frequency, size, and aging using the formula: Priority = (Frequency / Size) + Global_Age
Fields§
§core: CoreCacheMetrics
Core metrics common to all cache algorithms
global_age: f64
Current global age value
total_aging_events: u64
Total number of aging events (when global age is increased)
min_priority: f64
Current minimum priority in the cache
max_priority: f64
Current maximum priority in the cache
total_frequency: u64
Total frequency of all items (cumulative)
total_item_size_processed: u64
Total size of all items ever processed (for size-frequency analysis)
small_items_cached: u64
Number of small items (below average size) that were cached
large_items_cached: u64
Number of large items (above average size) that were cached
size_based_evictions: u64
Total number of size-based evictions (items evicted due to poor size/frequency ratio)
total_frequency_size_ratio: f64
Sum of all frequency/size ratios for efficiency analysis
Implementations§
Source§impl GdsfCacheMetrics
impl GdsfCacheMetrics
Sourcepub fn new(max_cache_size_bytes: u64) -> Self
pub fn new(max_cache_size_bytes: u64) -> Self
Creates a new GdsfCacheMetrics instance with the specified maximum cache size
§Arguments
max_cache_size_bytes
- The maximum allowed cache size in bytes
Sourcepub fn record_aging_event(&mut self, new_global_age: f64)
pub fn record_aging_event(&mut self, new_global_age: f64)
Records an aging event (when global age is increased due to eviction)
§Arguments
new_global_age
- The new global age value
Sourcepub fn record_item_access(&mut self, frequency: u64, size: u64, priority: f64)
pub fn record_item_access(&mut self, frequency: u64, size: u64, priority: f64)
Records processing of an item (frequency increment and size tracking)
§Arguments
frequency
- Current frequency of the itemsize
- Size of the item in bytespriority
- Calculated priority of the item
Sourcepub fn record_item_cached(&mut self, size: u64, average_size: f64)
pub fn record_item_cached(&mut self, size: u64, average_size: f64)
Records caching of an item with size classification
§Arguments
size
- Size of the cached item in bytesaverage_size
- Current average item size for classification
Sourcepub fn record_size_based_eviction(&mut self)
pub fn record_size_based_eviction(&mut self)
Records a size-based eviction
Sourcepub fn average_frequency(&self) -> f64
pub fn average_frequency(&self) -> f64
Calculates the average frequency across all processed items
§Returns
Average frequency per item access, or 0.0 if no items processed
Sourcepub fn average_item_size(&self) -> f64
pub fn average_item_size(&self) -> f64
Calculates the average size of processed items
§Returns
Average item size in bytes, or 0.0 if no items processed
Sourcepub fn average_frequency_size_ratio(&self) -> f64
pub fn average_frequency_size_ratio(&self) -> f64
Calculates the average frequency-to-size ratio
§Returns
Average frequency/size ratio, or 0.0 if no items processed
Sourcepub fn priority_range(&self) -> f64
pub fn priority_range(&self) -> f64
Sourcepub fn size_distribution_balance(&self) -> f64
pub fn size_distribution_balance(&self) -> f64
Calculates size distribution balance (small vs large items)
§Returns
Ratio of small items to total cached items, or 0.0 if no items cached
Sourcepub fn size_eviction_efficiency(&self) -> f64
pub fn size_eviction_efficiency(&self) -> f64
Sourcepub fn to_btreemap(&self) -> BTreeMap<String, f64>
pub fn to_btreemap(&self) -> BTreeMap<String, f64>
Converts GDSF metrics to a BTreeMap for reporting
This method returns all metrics relevant to the GDSF cache algorithm, including both core metrics and GDSF-specific size-frequency metrics.
Uses BTreeMap to ensure consistent, deterministic ordering of metrics.
§Returns
A BTreeMap containing all GDSF cache metrics as key-value pairs
Trait Implementations§
Source§impl CacheMetrics for GdsfCacheMetrics
impl CacheMetrics for GdsfCacheMetrics
Source§fn metrics(&self) -> BTreeMap<String, f64>
fn metrics(&self) -> BTreeMap<String, f64>
Returns all GDSF cache metrics as key-value pairs in deterministic order
§Returns
A BTreeMap containing all metrics tracked by this GDSF cache instance
Source§fn algorithm_name(&self) -> &'static str
fn algorithm_name(&self) -> &'static str
Returns the algorithm name for this cache implementation
§Returns
“GDSF” - identifying this as a Greedy Dual-Size Frequency cache
Source§impl Clone for GdsfCacheMetrics
impl Clone for GdsfCacheMetrics
Source§fn clone(&self) -> GdsfCacheMetrics
fn clone(&self) -> GdsfCacheMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more