pub struct CacheStats {
pub inserts: u64,
pub hits: u64,
pub misses: u64,
pub evictions: u64,
pub ttl_expired: u64,
}Expand description
Snapshot of cache counters at a point in time. Returned by
Cache::stats.
All fields are monotonically increasing u64s — they grow as the cache
is used and never decrement. Take two snapshots and subtract to get a
rate / per-window count. Designed for cheap export to prometheus,
metrics, or opentelemetry without forcing a dep choice on the
caller. Issue #40.
§Examples
use staticweaver::cache::Cache;
use std::time::Duration;
let mut cache: Cache<String, u32> = Cache::new(Duration::from_secs(60));
let _ = cache.insert("a".to_string(), 1);
let _ = cache.get(&"a".to_string()); // hit
let _ = cache.get(&"b".to_string()); // miss
let stats = cache.stats();
assert_eq!(stats.inserts, 1);
assert_eq!(stats.hits, 1);
assert_eq!(stats.misses, 1);Fields§
§inserts: u64Number of insert calls (new entries + updates).
hits: u64Number of get calls that returned Some for a live entry.
misses: u64Number of get calls that returned None (absent key, no hit).
evictions: u64Number of entries removed because they hit the capacity ceiling
(LRU evictions). Does not count TTL expirations — see
ttl_expired for those.
ttl_expired: u64Number of entries reaped by get finding them expired or by
remove_expired sweeping them.
Trait Implementations§
Source§impl Clone for CacheStats
impl Clone for CacheStats
impl Copy for CacheStats
Source§impl Debug for CacheStats
impl Debug for CacheStats
Source§impl Default for CacheStats
impl Default for CacheStats
impl Eq for CacheStats
Source§impl PartialEq for CacheStats
impl PartialEq for CacheStats
impl StructuralPartialEq for CacheStats
Auto Trait Implementations§
impl Freeze for CacheStats
impl RefUnwindSafe for CacheStats
impl Send for CacheStats
impl Sync for CacheStats
impl Unpin for CacheStats
impl UnsafeUnpin for CacheStats
impl UnwindSafe for CacheStats
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more