CacheStats

Struct CacheStats 

Source
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

Source

pub fn new() -> Self

Create a new stats instance with all counters at zero.

Source

pub fn record_hit(&self)

Record a cache hit.

Source

pub fn record_miss(&self)

Record a cache miss.

Source

pub fn record_eviction(&self)

Record an eviction (due to capacity).

Source

pub fn record_expiration(&self)

Record an expiration (due to TTL).

Source

pub fn record_set(&self)

Record a set operation.

Source

pub fn record_delete(&self)

Record a delete operation.

Source

pub fn increment_size(&self)

Increment the size counter.

Source

pub fn decrement_size(&self)

Decrement the size counter.

Source

pub fn set_size(&self, size: u64)

Set the size to a specific value.

Source

pub fn hits(&self) -> u64

Get the number of cache hits.

Source

pub fn misses(&self) -> u64

Get the number of cache misses.

Source

pub fn evictions(&self) -> u64

Get the number of evictions.

Source

pub fn expirations(&self) -> u64

Get the number of expirations.

Source

pub fn size(&self) -> u64

Get the current cache size.

Source

pub fn sets(&self) -> u64

Get the total number of set operations.

Source

pub fn deletes(&self) -> u64

Get the total number of delete operations.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CacheStats

Source§

fn default() -> CacheStats

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.