7#include <userver/utils/statistics/recentperiod.hpp>
8#include <userver/utils/statistics/writer.hpp>
10USERVER_NAMESPACE_BEGIN
12namespace cache::impl {
14struct ExpirableLruCacheStatisticsBase
final {
15 std::atomic<std::size_t> hits{0};
16 std::atomic<std::size_t> misses{0};
17 std::atomic<std::size_t> stale{0};
18 std::atomic<std::size_t> background_updates{0};
20 ExpirableLruCacheStatisticsBase();
22 ExpirableLruCacheStatisticsBase(
const ExpirableLruCacheStatisticsBase& other);
26 ExpirableLruCacheStatisticsBase& operator+=(
const ExpirableLruCacheStatisticsBase& other);
29struct ExpirableLruCacheStatistics
final {
30 ExpirableLruCacheStatisticsBase total;
31 utils::statistics::RecentPeriod<ExpirableLruCacheStatisticsBase, ExpirableLruCacheStatisticsBase> recent{
32 std::chrono::seconds(5),
33 std::chrono::seconds(60)};
36void CacheHit(ExpirableLruCacheStatistics& stats);
38void CacheMiss(ExpirableLruCacheStatistics& stats);
40void CacheStale(ExpirableLruCacheStatistics& stats);
42void DumpMetric(
utils::statistics::Writer& writer,
const ExpirableLruCacheStatistics& stats);