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, formats::parse::To<LruCacheConfig>);
36
37struct LruCacheConfigStatic final {
38 explicit LruCacheConfigStatic(const yaml_config::YamlConfig& config);
39 explicit LruCacheConfigStatic(const components::ComponentConfig& config);
40
41 std::size_t GetWaySize() const;
42
43 LruCacheConfig config;
44 std::size_t ways;
45 bool use_dynamic_config;
46};
47
48extern const dynamic_config::Key<std::unordered_map<std::string, LruCacheConfig>> kLruCacheConfigSet;
49
50std::optional<LruCacheConfig> GetLruConfig(const dynamic_config::Snapshot& config, const std::string& cache_name);
51
52} // namespace cache
53
54USERVER_NAMESPACE_END