CacheStats

Struct CacheStats 

Source
pub struct CacheStats {
    pub size: usize,
    pub capacity: usize,
    pub hits: u64,
    pub misses: u64,
    pub hit_rate: f64,
}
Expand description

Cache statistics.

Fields§

§size: usize

Current number of entries.

§capacity: usize

Maximum capacity.

§hits: u64

Total cache hits.

§misses: u64

Total cache misses.

§hit_rate: f64

Hit rate (0.0 to 1.0).

Implementations§

Source§

impl CacheStats

Source

pub fn new(size: usize, capacity: usize, hits: u64, misses: u64) -> Self

Create new cache statistics.

§Example
use chie_shared::types::cache::CacheStats;

let stats = CacheStats::new(750, 1000, 8500, 1500);

assert_eq!(stats.size, 750);
assert_eq!(stats.capacity, 1000);
assert_eq!(stats.hits, 8500);
assert_eq!(stats.misses, 1500);
assert_eq!(stats.hit_rate, 0.85);
assert_eq!(stats.total_requests(), 10000);
assert!((stats.miss_rate() - 0.15).abs() < 1e-10);
assert_eq!(stats.fill_percentage(), 0.75);
Source

pub fn empty(capacity: usize) -> Self

Create empty cache statistics.

Source

pub fn is_full(&self) -> bool

Check if cache is full.

Source

pub fn is_empty(&self) -> bool

Check if cache is empty.

Source

pub fn fill_percentage(&self) -> f64

Get the fill percentage (0.0 to 1.0).

Source

pub fn total_requests(&self) -> u64

Get total requests (hits + misses).

Source

pub fn miss_rate(&self) -> f64

Get miss rate (0.0 to 1.0).

Source

pub fn efficiency_score(&self) -> f64

Calculate efficiency score (0.0 to 100.0).

Combines hit rate (70% weight) and capacity utilization (30% weight).

§Example
use chie_shared::types::cache::CacheStats;

// High efficiency: good hit rate and good utilization
let stats1 = CacheStats::new(900, 1000, 9000, 1000);
assert_eq!(stats1.efficiency_score(), 90.0 * 0.7 + 0.9 * 30.0);

// Medium efficiency: good hit rate but low utilization
let stats2 = CacheStats::new(300, 1000, 900, 100);
assert_eq!(stats2.efficiency_score(), 0.9 * 70.0 + 0.3 * 30.0);

// Low efficiency: poor hit rate
let stats3 = CacheStats::new(500, 1000, 300, 700);
assert_eq!(stats3.efficiency_score(), 0.3 * 70.0 + 0.5 * 30.0);

Trait Implementations§

Source§

impl Clone for CacheStats

Source§

fn clone(&self) -> CacheStats

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
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() -> Self

Returns the “default value” for a type. 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 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 · 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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,