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+=(const ExpirableLruCacheStatisticsBase& other);
27};
28
29struct ExpirableLruCacheStatistics final {
30 ExpirableLruCacheStatisticsBase total;
31 utils::statistics::RecentPeriod<ExpirableLruCacheStatisticsBase, ExpirableLruCacheStatisticsBase> recent{
32 std::chrono::seconds(5),
33 std::chrono::seconds(60)};
34};
35
36void CacheHit(ExpirableLruCacheStatistics& stats);
37
38void CacheMiss(ExpirableLruCacheStatistics& stats);
39
40void CacheStale(ExpirableLruCacheStatistics& stats);
41
42void DumpMetric(utils::statistics::Writer& writer, const ExpirableLruCacheStatistics& stats);
43
44} // namespace cache::impl
45
46USERVER_NAMESPACE_END