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: u64Lookups served from the cache.
misses: u64Lookups that missed and fell through to the wrapped index.
evictions: u64Entries discarded by the eviction policy to make room over the cache’s lifetime.
len: usizeEntries currently held.
capacity: usizeMaximum entries the cache will hold; 0 means caching is disabled.
Implementations§
Source§impl CacheStats
impl CacheStats
Sourcepub fn lookups(&self) -> u64
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);Sourcepub fn hit_rate(&self) -> f64
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
impl Clone for CacheStats
Source§fn clone(&self) -> CacheStats
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for CacheStats
Source§impl Debug for CacheStats
impl Debug for CacheStats
Source§impl<'de> Deserialize<'de> for CacheStats
impl<'de> Deserialize<'de> for CacheStats
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for CacheStats
Source§impl PartialEq for CacheStats
impl PartialEq for CacheStats
Source§fn eq(&self, other: &CacheStats) -> bool
fn eq(&self, other: &CacheStats) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for CacheStats
impl Serialize 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