persistent-cache-cpp
core::PersistentCacheStats Class Reference

Class that provides (read-only) access to cache statistics and settings. More...

#include <core/persistent_cache_stats.h>

Public Member Functions

Construction, Copy and Assignment

Copy and assignment have the usual value semantics. The default constructor creates an instance with an empty cache path, lru_only policy, and the remaining values set to zero.

 PersistentCacheStats ()
 
 PersistentCacheStats (PersistentCacheStats const &)
 
 PersistentCacheStats (PersistentCacheStats &&) noexcept
 
PersistentCacheStatsoperator= (PersistentCacheStats const &)
 
PersistentCacheStatsoperator= (PersistentCacheStats &&)
 

Accessors

typedef std::vector< uint32_t > Histogram
 Histogram of the size distribution of cache entries.
 
typedef std::vector< std::pair< int32_t, int32_t > > HistogramBounds
 Lower and upper bounds for the bins in the histogram.
 
static constexpr unsigned NUM_BINS = 74
 The number of bins in a histogram.
 
std::string cache_path () const
 Returns the path to the cache directory.
 
CacheDiscardPolicy policy () const noexcept
 Returns the discard policy (lru_only or lru_ttl).
 
int64_t size () const noexcept
 Returns the number of entries (including expired ones).
 
int64_t size_in_bytes () const noexcept
 Returns the size of all entries (including expired ones).
 
int64_t max_size_in_bytes () const noexcept
 Returns the maximum size of the cache.
 
int64_t hits () const noexcept
 Returns the number of hits since the statistics were last reset.
 
int64_t misses () const noexcept
 Returns the number of misses since the statistics were last reset.
 
int64_t hits_since_last_miss () const noexcept
 Returns the number of consecutive hits since the last miss.
 
int64_t misses_since_last_hit () const noexcept
 Returns the number of consecutive misses since the last hit.
 
int64_t longest_hit_run () const noexcept
 Returns the largest number of consecutive hits.
 
int64_t longest_miss_run () const noexcept
 Returns the largest number of consecutive misses.
 
int64_t hit_runs () const noexcept
 Returns the number of hit runs.
 
int64_t miss_runs () const noexcept
 Returns the number of miss runs.
 
double avg_hit_run_length () const noexcept
 Returns a rolling average of the hit run length.
 
double avg_miss_run_length () const noexcept
 Returns a rolling average of the miss run length.
 
int64_t ttl_evictions () const noexcept
 Returns the number of entries that were evicted due to being expired.
 
int64_t lru_evictions () const noexcept
 Returns the number of entries that were evicted due to being least recently used.
 
std::chrono::system_clock::time_point most_recent_hit_time () const noexcept
 Returns the timestamp of the most recent hit.
 
std::chrono::system_clock::time_point most_recent_miss_time () const noexcept
 Returns the timestamp of the most recent miss.
 
std::chrono::system_clock::time_point longest_hit_run_time () const noexcept
 Returns the time of the longest hit run.
 
std::chrono::system_clock::time_point longest_miss_run_time () const noexcept
 Returns the time of the longest miss run.
 
Histogram const & histogram () const noexcept
 Returns a histogram for the entries in the cache.
 
static HistogramBounds const & histogram_bounds () noexcept
 Returns the bounds for each bin a histogram.
 

Detailed Description

Class that provides (read-only) access to cache statistics and settings.

Member Typedef Documentation

◆ Histogram

typedef std::vector<uint32_t> core::PersistentCacheStats::Histogram

Histogram of the size distribution of cache entries.

The histogram uses a logarithmic scale and contains the number of entries in the cache, with entries grouped by size into a number of bins as follows:

Index Entry size in bytes
0 1..9
1 10..19
2 20..29
... ...
9 90..99
10 100..199
11 200..200
... ...
18 900..999
19 1,000..1,999
20 2,000..2,999
... ...
27 9,000..9,999
28 10,000..19,999
29 20,000..29,999
... ...
72 900,000,000..999,999,999
73 1,000,000,000..

Index 0 contains the number of entries < 10 bytes. Thereafter, the histogram contains 9 bins for each power of 10, plus a final bin at index 73 that contains the number of entries ≥ 109 bytes.

◆ HistogramBounds

typedef std::vector<std::pair<int32_t, int32_t> > core::PersistentCacheStats::HistogramBounds

Lower and upper bounds for the bins in the histogram.

Each pair contains the lower and upper (inclusive) bound of the corresponding bin of the values returned by histogram().

Constructor & Destructor Documentation

◆ PersistentCacheStats() [1/3]

core::PersistentCacheStats::PersistentCacheStats ( )

◆ PersistentCacheStats() [2/3]

core::PersistentCacheStats::PersistentCacheStats ( PersistentCacheStats const &  )

◆ PersistentCacheStats() [3/3]

core::PersistentCacheStats::PersistentCacheStats ( PersistentCacheStats &&  )
noexcept

Member Function Documentation

◆ avg_hit_run_length()

double core::PersistentCacheStats::avg_hit_run_length ( ) const
noexcept

Returns a rolling average of the hit run length.

◆ avg_miss_run_length()

double core::PersistentCacheStats::avg_miss_run_length ( ) const
noexcept

Returns a rolling average of the miss run length.

◆ cache_path()

std::string core::PersistentCacheStats::cache_path ( ) const

Returns the path to the cache directory.

◆ histogram()

Histogram const & core::PersistentCacheStats::histogram ( ) const
noexcept

Returns a histogram for the entries in the cache.

◆ histogram_bounds()

static HistogramBounds const & core::PersistentCacheStats::histogram_bounds ( )
staticnoexcept

Returns the bounds for each bin a histogram.

This method returns the same vector each time; it is provided as a convenience method to make it easier to add labels to a histogram for display. The returned pairs use inclusive ranges, that is, pair.second is the largest possible size of the bin.

◆ hit_runs()

int64_t core::PersistentCacheStats::hit_runs ( ) const
noexcept

Returns the number of hit runs.

◆ hits()

int64_t core::PersistentCacheStats::hits ( ) const
noexcept

Returns the number of hits since the statistics were last reset.

◆ hits_since_last_miss()

int64_t core::PersistentCacheStats::hits_since_last_miss ( ) const
noexcept

Returns the number of consecutive hits since the last miss.

◆ longest_hit_run()

int64_t core::PersistentCacheStats::longest_hit_run ( ) const
noexcept

Returns the largest number of consecutive hits.

◆ longest_hit_run_time()

std::chrono::system_clock::time_point core::PersistentCacheStats::longest_hit_run_time ( ) const
noexcept

Returns the time of the longest hit run.

◆ longest_miss_run()

int64_t core::PersistentCacheStats::longest_miss_run ( ) const
noexcept

Returns the largest number of consecutive misses.

◆ longest_miss_run_time()

std::chrono::system_clock::time_point core::PersistentCacheStats::longest_miss_run_time ( ) const
noexcept

Returns the time of the longest miss run.

◆ lru_evictions()

int64_t core::PersistentCacheStats::lru_evictions ( ) const
noexcept

Returns the number of entries that were evicted due to being least recently used.

◆ max_size_in_bytes()

int64_t core::PersistentCacheStats::max_size_in_bytes ( ) const
noexcept

Returns the maximum size of the cache.

◆ miss_runs()

int64_t core::PersistentCacheStats::miss_runs ( ) const
noexcept

Returns the number of miss runs.

◆ misses()

int64_t core::PersistentCacheStats::misses ( ) const
noexcept

Returns the number of misses since the statistics were last reset.

◆ misses_since_last_hit()

int64_t core::PersistentCacheStats::misses_since_last_hit ( ) const
noexcept

Returns the number of consecutive misses since the last hit.

◆ most_recent_hit_time()

std::chrono::system_clock::time_point core::PersistentCacheStats::most_recent_hit_time ( ) const
noexcept

Returns the timestamp of the most recent hit.

◆ most_recent_miss_time()

std::chrono::system_clock::time_point core::PersistentCacheStats::most_recent_miss_time ( ) const
noexcept

Returns the timestamp of the most recent miss.

◆ operator=() [1/2]

PersistentCacheStats & core::PersistentCacheStats::operator= ( PersistentCacheStats &&  )

◆ operator=() [2/2]

PersistentCacheStats & core::PersistentCacheStats::operator= ( PersistentCacheStats const &  )

◆ policy()

CacheDiscardPolicy core::PersistentCacheStats::policy ( ) const
noexcept

Returns the discard policy (lru_only or lru_ttl).

◆ size()

int64_t core::PersistentCacheStats::size ( ) const
noexcept

Returns the number of entries (including expired ones).

◆ size_in_bytes()

int64_t core::PersistentCacheStats::size_in_bytes ( ) const
noexcept

Returns the size of all entries (including expired ones).

◆ ttl_evictions()

int64_t core::PersistentCacheStats::ttl_evictions ( ) const
noexcept

Returns the number of entries that were evicted due to being expired.

Member Data Documentation

◆ NUM_BINS

constexpr unsigned core::PersistentCacheStats::NUM_BINS = 74
staticconstexpr

The number of bins in a histogram.


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