pub struct CacheStats { /* private fields */ }Expand description
Statistics for cache operations.
All counters are atomic and can be safely accessed from multiple threads.
Use Cache::stats() to get a snapshot of the current statistics.
§Example
ⓘ
let cache = Cache::new(CacheConfig::default());
cache.set("key", "value");
let stats = cache.stats();
println!("Cache size: {}", stats.size());Implementations§
Source§impl CacheStats
impl CacheStats
Sourcepub fn record_hit(&self)
pub fn record_hit(&self)
Record a cache hit.
Sourcepub fn record_miss(&self)
pub fn record_miss(&self)
Record a cache miss.
Sourcepub fn record_eviction(&self)
pub fn record_eviction(&self)
Record an eviction (due to capacity).
Sourcepub fn record_expiration(&self)
pub fn record_expiration(&self)
Record an expiration (due to TTL).
Sourcepub fn record_set(&self)
pub fn record_set(&self)
Record a set operation.
Sourcepub fn record_delete(&self)
pub fn record_delete(&self)
Record a delete operation.
Sourcepub fn increment_size(&self)
pub fn increment_size(&self)
Increment the size counter.
Sourcepub fn decrement_size(&self)
pub fn decrement_size(&self)
Decrement the size counter.
Sourcepub fn expirations(&self) -> u64
pub fn expirations(&self) -> u64
Get the number of expirations.
Sourcepub fn hit_rate(&self) -> f64
pub fn hit_rate(&self) -> f64
Calculate the hit rate as a percentage (0.0 to 100.0). Returns 0.0 if no operations have been performed.
Sourcepub fn snapshot(&self) -> StatsSnapshot
pub fn snapshot(&self) -> StatsSnapshot
Create a snapshot of the current statistics. This is useful for serialization or logging.
Trait Implementations§
Source§impl Debug for CacheStats
impl Debug for CacheStats
Source§impl Default for CacheStats
impl Default for CacheStats
Source§fn default() -> CacheStats
fn default() -> CacheStats
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for CacheStats
impl RefUnwindSafe for CacheStats
impl Send for CacheStats
impl Sync for CacheStats
impl Unpin 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