Skip to main content

CacheStats

Struct CacheStats 

Source
pub struct CacheStats {
    pub hits: u64,
    pub misses: u64,
    pub evictions: u64,
    pub len: usize,
    pub capacity: usize,
}
Expand description

A point-in-time snapshot of a CachedIndex’s cache.

Returned by CachedIndex::cache_stats. hits and misses are monotonic counters over the cache’s lifetime; len and capacity describe its current occupancy. Use hit_rate to turn the counters into a ratio for tuning.

§Examples

use iqdb_cache::CacheStats;

let stats = CacheStats {
    hits: 75,
    misses: 25,
    evictions: 8,
    len: 64,
    capacity: 128,
};
assert_eq!(stats.lookups(), 100);
assert!((stats.hit_rate() - 0.75).abs() < f64::EPSILON);

Fields§

§hits: u64

Lookups served from the cache.

§misses: u64

Lookups that missed and fell through to the wrapped index.

§evictions: u64

Entries discarded by the eviction policy to make room over the cache’s lifetime.

§len: usize

Entries currently held.

§capacity: usize

Maximum entries the cache will hold; 0 means caching is disabled.

Implementations§

Source§

impl CacheStats

Source

pub fn lookups(&self) -> u64

Total lookups observed: hits + misses (saturating).

§Examples
use iqdb_cache::CacheStats;

let stats = CacheStats { hits: 3, misses: 1, evictions: 0, len: 4, capacity: 8 };
assert_eq!(stats.lookups(), 4);
Source

pub fn hit_rate(&self) -> f64

The fraction of lookups served from cache, in 0.0..=1.0.

Returns 0.0 when there have been no lookups, so the result is always finite and safe to display.

§Examples
use iqdb_cache::CacheStats;

let warm = CacheStats { hits: 9, misses: 1, evictions: 0, len: 10, capacity: 16 };
assert!((warm.hit_rate() - 0.9).abs() < 1e-9);

let cold = CacheStats { hits: 0, misses: 0, evictions: 0, len: 0, capacity: 16 };
assert_eq!(cold.hit_rate(), 0.0);

Trait Implementations§

Source§

impl Clone for CacheStats

Source§

fn clone(&self) -> CacheStats

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CacheStats

Source§

impl Debug for CacheStats

Source§

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

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

impl<'de> Deserialize<'de> for CacheStats

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for CacheStats

Source§

impl PartialEq for CacheStats

Source§

fn eq(&self, other: &CacheStats) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CacheStats

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CacheStats

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error