Skip to main content

CacheStats

Struct CacheStats 

Source
pub struct CacheStats {
Show 21 fields pub hits: u64, pub misses: u64, pub loads: u64, pub single_flight_joins: u64, pub stale_load_discards: u64, pub invalidations: u64, pub evictions: u64, pub oversize_rejections: u64, pub events_published: u64, pub event_subscriber_lagged: u64, pub distributed_invalidations_published: u64, pub distributed_invalidations_received: u64, pub distributed_invalidations_applied: u64, pub distributed_invalidation_lagged: u64, pub distributed_invalidation_decode_errors: u64, pub distributed_invalidation_publish_failures: u64, pub distributed_invalidation_receiver_closed: u64, pub consistency_wait_successes: u64, pub consistency_wait_timeouts: u64, pub consistency_degraded_reads: u64, pub consistency_fail_closed: u64,
}
Expand description

Snapshot of lightweight cache counters.

The counters are intentionally lightweight and approximate enough for local observability. They are not intended to be a durable metrics store.

§Example

use hydracache_core::CacheStats;

let stats = CacheStats::default();
assert_eq!(stats.hits, 0);
assert_eq!(stats.single_flight_joins, 0);
assert_eq!(stats.oversize_rejections, 0);
assert_eq!(stats.consistency_wait_successes, 0);
assert_eq!(stats.events_published, 0);
assert_eq!(stats.distributed_invalidations_published, 0);
assert_eq!(stats.distributed_invalidation_lagged, 0);
assert_eq!(stats.distributed_invalidation_decode_errors, 0);
assert_eq!(stats.total_requests(), 0);
assert_eq!(stats.hit_ratio(), None);

Fields§

§hits: u64

Successful cache lookups.

§misses: u64

Cache lookups that did not return a usable value.

§loads: u64

Loader closures executed by get_or_load.

§single_flight_joins: u64

Calls that joined an already running single-flight load.

§stale_load_discards: u64

Loader results skipped because their invalidation generation became stale.

§invalidations: u64

Entries removed by invalidation APIs.

§evictions: u64

Entries observed as evicted by the backend.

v0 does not wire backend eviction listeners yet, so this remains zero.

§oversize_rejections: u64

Entries rejected before insertion because encoded bytes exceeded max_entry_bytes.

§events_published: u64

Cache events delivered to at least one subscriber.

§event_subscriber_lagged: u64

Event notifications skipped by slow subscribers.

§distributed_invalidations_published: u64

Invalidation messages published to an attached bus.

§distributed_invalidations_received: u64

Invalidation messages received from an attached bus.

§distributed_invalidations_applied: u64

Received invalidation messages applied to the local cache.

§distributed_invalidation_lagged: u64

Invalidation messages skipped because a bus receiver lagged behind.

§distributed_invalidation_decode_errors: u64

Invalidation transport frames that could not be decoded.

§distributed_invalidation_publish_failures: u64

Invalidation publish attempts that returned an error.

§distributed_invalidation_receiver_closed: u64

Times an attached bus receiver reported that the stream closed.

§consistency_wait_successes: u64

Consistency-token waits that observed the requested generation.

§consistency_wait_timeouts: u64

Consistency-token waits that timed out.

§consistency_degraded_reads: u64

Consistency-token reads that returned a degraded value.

§consistency_fail_closed: u64

Consistency-token reads that failed closed instead of serving stale data.

Implementations§

Source§

impl CacheStats

Source

pub fn total_requests(&self) -> u64

Return the number of lookup attempts represented by this snapshot.

This is hits + misses, so it intentionally does not include loader executions, invalidations, or backend evictions.

§Example
use hydracache_core::CacheStats;

let stats = CacheStats {
    hits: 3,
    misses: 1,
    ..CacheStats::default()
};

assert_eq!(stats.total_requests(), 4);
Source

pub fn hit_ratio(&self) -> Option<f64>

Return the cache hit ratio for this snapshot.

Returns None when no lookup has happened yet. Otherwise the value is hits / (hits + misses) in the 0.0..=1.0 range.

§Example
use hydracache_core::CacheStats;

let stats = CacheStats {
    hits: 3,
    misses: 1,
    ..CacheStats::default()
};

assert_eq!(stats.hit_ratio(), Some(0.75));
Source

pub fn has_single_flight_activity(&self) -> bool

Return whether at least one caller joined an existing single-flight load.

This is a compact way to check that concurrent misses were deduplicated.

Source

pub fn has_stale_load_discards(&self) -> bool

Return whether a stale loader result was discarded after invalidation.

Source

pub fn has_oversize_rejections(&self) -> bool

Return whether at least one encoded value was rejected before insertion.

Source

pub fn has_event_subscriber_lag(&self) -> bool

Return whether at least one event subscriber lagged behind the event bus.

Source

pub fn has_distributed_invalidation_activity(&self) -> bool

Return whether this cache has published or received bus invalidations.

Source

pub fn has_distributed_invalidation_bus_issues(&self) -> bool

Return whether this cache observed invalidation bus health issues.

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 Default for CacheStats

Source§

fn default() -> CacheStats

Returns the “default value” for a type. 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 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.