pub struct CacheMetrics { /* private fields */ }Expand description
Atomic cache metrics counters.
All fields use AtomicU64 with Relaxed ordering for maximum throughput;
consistency is guaranteed only when you call snapshot.
§Example
use oximedia_cache::cache_metrics::CacheMetrics;
let m = CacheMetrics::new();
m.record_hit(500);
m.record_miss(1_200);
let s = m.snapshot();
assert!((s.hit_rate - 0.5).abs() < 1e-9);Implementations§
Source§impl CacheMetrics
impl CacheMetrics
Create a new CacheMetrics wrapped in an Arc for sharing across threads.
Sourcepub fn record_hit(&self, latency_ns: u64)
pub fn record_hit(&self, latency_ns: u64)
Record a cache hit with the given lookup latency in nanoseconds.
Increments the hit counter and accumulates latency for average latency calculation.
Sourcepub fn record_miss(&self, latency_ns: u64)
pub fn record_miss(&self, latency_ns: u64)
Record a cache miss with the given lookup latency in nanoseconds.
Increments the miss counter and accumulates latency for average latency calculation.
Sourcepub fn record_eviction(&self)
pub fn record_eviction(&self)
Record one cache eviction.
Sourcepub fn hit_rate(&self) -> f64
pub fn hit_rate(&self) -> f64
Return the current hit rate as a fraction in [0.0, 1.0].
Returns 0.0 when no lookups have been recorded yet.
Sourcepub fn miss_rate(&self) -> f64
pub fn miss_rate(&self) -> f64
Return the current miss rate as a fraction in [0.0, 1.0].
Returns 0.0 when no lookups have been recorded yet.
Sourcepub fn avg_latency_ns(&self) -> f64
pub fn avg_latency_ns(&self) -> f64
Return the average lookup latency in nanoseconds across all recorded operations (hits and misses combined).
Returns 0.0 when no operations have been recorded.
Sourcepub fn total_hits(&self) -> u64
pub fn total_hits(&self) -> u64
Return the total number of recorded hits.
Sourcepub fn total_misses(&self) -> u64
pub fn total_misses(&self) -> u64
Return the total number of recorded misses.
Sourcepub fn total_evictions(&self) -> u64
pub fn total_evictions(&self) -> u64
Return the total number of recorded evictions.
Sourcepub fn eviction_rate(&self) -> f64
pub fn eviction_rate(&self) -> f64
Return the eviction rate: evictions / (hits + misses).
Returns 0.0 when no lookups have been recorded yet.
Sourcepub fn snapshot(&self) -> CacheMetricsSnapshot
pub fn snapshot(&self) -> CacheMetricsSnapshot
Capture an immutable point-in-time snapshot of the current metrics.