pub struct CacheMetrics {
pub hits: u64,
pub misses: u64,
pub total_cached: u64,
pub invalidations: u64,
pub size: usize,
pub memory_bytes: usize,
}Expand description
Cache metrics for monitoring.
Exposed via API for observability and debugging.
Fields§
§hits: u64Number of cache hits (returned cached result).
misses: u64Number of cache misses (executed query).
total_cached: u64Total entries cached across all time.
invalidations: u64Number of invalidations triggered.
size: usizeCurrent size of cache (number of entries).
memory_bytes: usizeEstimated memory usage in bytes.
This is a rough estimate based on cache key lengths and entry counts. Actual memory usage may vary based on result sizes.
Implementations§
Source§impl CacheMetrics
impl CacheMetrics
Sourcepub fn hit_rate(&self) -> f64
pub fn hit_rate(&self) -> f64
Calculate cache hit rate.
Returns ratio of hits to total requests (0.0 to 1.0).
§Returns
1.0if all requests were hits0.0if all requests were misses0.0if no requests yet
§Example
use fraiseql_core::cache::CacheMetrics;
let metrics = CacheMetrics {
hits: 80,
misses: 20,
total_cached: 100,
invalidations: 5,
size: 95,
memory_bytes: 1_000_000,
};
assert_eq!(metrics.hit_rate(), 0.8); // 80% hit rateSourcepub fn is_healthy(&self) -> bool
pub fn is_healthy(&self) -> bool
Check if cache is performing well.
Returns true if hit rate is above 60% (reasonable threshold).
§Example
use fraiseql_core::cache::CacheMetrics;
let good_metrics = CacheMetrics {
hits: 80,
misses: 20,
total_cached: 100,
invalidations: 5,
size: 95,
memory_bytes: 1_000_000,
};
assert!(good_metrics.is_healthy()); // 80% > 60%Trait Implementations§
Source§impl Clone for CacheMetrics
impl Clone for CacheMetrics
Source§fn clone(&self) -> CacheMetrics
fn clone(&self) -> CacheMetrics
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CacheMetrics
impl Debug for CacheMetrics
Source§impl<'de> Deserialize<'de> for CacheMetrics
impl<'de> Deserialize<'de> for CacheMetrics
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
Auto Trait Implementations§
impl Freeze for CacheMetrics
impl RefUnwindSafe for CacheMetrics
impl Send for CacheMetrics
impl Sync for CacheMetrics
impl Unpin for CacheMetrics
impl UnsafeUnpin for CacheMetrics
impl UnwindSafe for CacheMetrics
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