userver: userver/cache/lru_cache_statistics.hpp Source File
Loading...
Searching...
No Matches
lru_cache_statistics.hpp
1#pragma once
2
3#include <atomic>
4#include <chrono>
5#include <cstddef>
6
7#include <userver/utils/statistics/recentperiod.hpp>
8#include <userver/utils/statistics/writer.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace cache::impl {
13
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};
19
20 ExpirableLruCacheStatisticsBase();
21
22 ExpirableLruCacheStatisticsBase(const ExpirableLruCacheStatisticsBase& other);
23
24 void Reset();
25
26 ExpirableLruCacheStatisticsBase& operator+=(
27 const ExpirableLruCacheStatisticsBase& other);
28};
29
30struct ExpirableLruCacheStatistics final {
31 ExpirableLruCacheStatisticsBase total;
32 utils::statistics::RecentPeriod<ExpirableLruCacheStatisticsBase,
33 ExpirableLruCacheStatisticsBase>
34 recent{std::chrono::seconds(5), std::chrono::seconds(60)};
35};
36
37void CacheHit(ExpirableLruCacheStatistics& stats);
38
39void CacheMiss(ExpirableLruCacheStatistics& stats);
40
41void CacheStale(ExpirableLruCacheStatistics& stats);
42
43void DumpMetric(utils::statistics::Writer& writer,
44 const ExpirableLruCacheStatistics& stats);
45
46} // namespace cache::impl
47
48USERVER_NAMESPACE_END