userver: userver/cache/lru_cache_config.hpp Source File
Loading...
Searching...
No Matches
lru_cache_config.hpp
1#pragma once
2
3#include <chrono>
4#include <cstddef>
5#include <optional>
6#include <unordered_map>
7
8#include <userver/components/component_fwd.hpp>
9#include <userver/dynamic_config/snapshot.hpp>
10#include <userver/formats/json_fwd.hpp>
11#include <userver/yaml_config/fwd.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace cache {
16
17enum class BackgroundUpdateMode {
18 kEnabled,
19 kDisabled,
20};
21
22struct LruCacheConfig final {
23 explicit LruCacheConfig(const yaml_config::YamlConfig& config);
24 explicit LruCacheConfig(const components::ComponentConfig& config);
25
26 explicit LruCacheConfig(const formats::json::Value& value);
27
28 std::size_t GetWaySize(std::size_t ways) const;
29
30 std::size_t size;
31 std::chrono::milliseconds lifetime;
32 BackgroundUpdateMode background_update;
33};
34
35LruCacheConfig Parse(const formats::json::Value& value,
36 formats::parse::To<LruCacheConfig>);
37
38struct LruCacheConfigStatic final {
39 explicit LruCacheConfigStatic(const yaml_config::YamlConfig& config);
40 explicit LruCacheConfigStatic(const components::ComponentConfig& config);
41
42 std::size_t GetWaySize() const;
43
44 LruCacheConfig config;
45 std::size_t ways;
46 bool use_dynamic_config;
47};
48
49extern const dynamic_config::Key<
50 std::unordered_map<std::string, LruCacheConfig>>
51 kLruCacheConfigSet;
52
53std::optional<LruCacheConfig> GetLruConfig(
54 const dynamic_config::Snapshot& config, const std::string& cache_name);
55
56} // namespace cache
57
58USERVER_NAMESPACE_END