PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::services::cache::cache_stats Struct Reference

Statistics for cache performance monitoring. More...

#include <simple_lru_cache.h>

Collaboration diagram for kcenon::pacs::services::cache::cache_stats:
Collaboration graph

Public Member Functions

double hit_rate () const noexcept
 Calculate the cache hit rate.
 
std::uint64_t total_accesses () const noexcept
 Get total number of cache accesses (hits + misses)
 
void reset () noexcept
 Reset all statistics to zero.
 

Public Attributes

std::atomic< std::uint64_t > hits {0}
 Number of cache hits.
 
std::atomic< std::uint64_t > misses {0}
 Number of cache misses.
 
std::atomic< std::uint64_t > insertions {0}
 Number of insertions.
 
std::atomic< std::uint64_t > evictions {0}
 Number of LRU evictions.
 
std::atomic< std::uint64_t > expirations {0}
 Number of TTL expirations.
 
std::atomic< std::size_t > current_size {0}
 Current number of entries.
 

Detailed Description

Statistics for cache performance monitoring.

All counters are atomic to allow lock-free reading of statistics while the cache is being modified.

Definition at line 78 of file simple_lru_cache.h.

Member Function Documentation

◆ hit_rate()

double kcenon::pacs::services::cache::cache_stats::hit_rate ( ) const
inlinenodiscardnoexcept

Calculate the cache hit rate.

Returns
Hit rate as a percentage (0.0 to 100.0), or 0.0 if no accesses
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/services/cache/simple_lru_cache.h.

Definition at line 90 of file simple_lru_cache.h.

90 {
91 const auto total_hits = hits.load(std::memory_order_relaxed);
92 const auto total_misses = misses.load(std::memory_order_relaxed);
93 const auto total = total_hits + total_misses;
94 if (total == 0) {
95 return 0.0;
96 }
97 return (static_cast<double>(total_hits) / static_cast<double>(total)) * 100.0;
98 }
std::atomic< std::uint64_t > hits
Number of cache hits.
std::atomic< std::uint64_t > misses
Number of cache misses.

References hits, and misses.

Referenced by kcenon::pacs::services::cache::query_cache::hit_rate(), and kcenon::pacs::services::cache::simple_lru_cache< Key, Value, Hash, KeyEqual >::hit_rate().

Here is the caller graph for this function:

◆ reset()

void kcenon::pacs::services::cache::cache_stats::reset ( )
inlinenoexcept

Reset all statistics to zero.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/services/cache/simple_lru_cache.h.

Definition at line 112 of file simple_lru_cache.h.

112 {
113 hits.store(0, std::memory_order_relaxed);
114 misses.store(0, std::memory_order_relaxed);
115 insertions.store(0, std::memory_order_relaxed);
116 evictions.store(0, std::memory_order_relaxed);
117 expirations.store(0, std::memory_order_relaxed);
118 // Note: current_size is not reset as it reflects actual cache state
119 }
std::atomic< std::uint64_t > evictions
Number of LRU evictions.
std::atomic< std::uint64_t > expirations
Number of TTL expirations.
std::atomic< std::uint64_t > insertions
Number of insertions.

References evictions, expirations, hits, insertions, and misses.

Referenced by kcenon::pacs::services::cache::simple_lru_cache< Key, Value, Hash, KeyEqual >::reset_stats().

Here is the caller graph for this function:

◆ total_accesses()

std::uint64_t kcenon::pacs::services::cache::cache_stats::total_accesses ( ) const
inlinenodiscardnoexcept

Get total number of cache accesses (hits + misses)

Returns
Total access count
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/services/cache/simple_lru_cache.h.

Definition at line 104 of file simple_lru_cache.h.

104 {
105 return hits.load(std::memory_order_relaxed) +
106 misses.load(std::memory_order_relaxed);
107 }

References hits, and misses.

Member Data Documentation

◆ current_size

◆ evictions

std::atomic<std::uint64_t> kcenon::pacs::services::cache::cache_stats::evictions {0}

◆ expirations

◆ hits

std::atomic<std::uint64_t> kcenon::pacs::services::cache::cache_stats::hits {0}

◆ insertions

◆ misses

std::atomic<std::uint64_t> kcenon::pacs::services::cache::cache_stats::misses {0}

The documentation for this struct was generated from the following file: