userver: userver/cache/cache_config.hpp Source File
Loading...
Searching...
No Matches
cache_config.hpp
1#pragma once
2
3#include <chrono>
4#include <optional>
5#include <stdexcept>
6#include <string>
7#include <unordered_map>
8
9#include <userver/cache/update_type.hpp>
10#include <userver/dynamic_config/snapshot.hpp>
11#include <userver/formats/json_fwd.hpp>
12#include <userver/yaml_config/fwd.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace dump {
17struct Config;
18} // namespace dump
19
20namespace cache {
21
22class ConfigError : public std::logic_error {
23 public:
24 using std::logic_error::logic_error;
25};
26
27enum class FirstUpdateMode {
28 kRequired,
29 kBestEffort,
30 kSkip,
31};
32
33FirstUpdateMode Parse(const yaml_config::YamlConfig& config,
34 formats::parse::To<FirstUpdateMode>);
35
36std::string_view ToString(FirstUpdateMode);
37
38enum class FirstUpdateType {
39 kFull,
40 kIncremental,
41 kIncrementalThenAsyncFull,
42};
43
44FirstUpdateType Parse(const yaml_config::YamlConfig& config,
45 formats::parse::To<FirstUpdateType>);
46
47std::string_view ToString(FirstUpdateType);
48
49struct ConfigPatch final {
50 std::chrono::milliseconds update_interval;
51 std::chrono::milliseconds update_jitter;
52 std::chrono::milliseconds full_update_interval;
53 std::chrono::milliseconds full_update_jitter;
54 std::optional<std::chrono::milliseconds> exception_interval;
55 bool updates_enabled;
56 std::uint64_t alert_on_failing_to_update_times;
57};
58
59ConfigPatch Parse(const formats::json::Value& value,
60 formats::parse::To<ConfigPatch>);
61
62struct Config final {
63 explicit Config(const yaml_config::YamlConfig& config,
64 const std::optional<dump::Config>& dump_config);
65
66 Config MergeWith(const ConfigPatch& patch) const;
67
68 AllowedUpdateTypes allowed_update_types;
69 bool allow_first_update_failure;
70 std::optional<bool> force_periodic_update;
71 bool config_updates_enabled;
72 bool has_pre_assign_check;
73 std::optional<std::string> task_processor_name;
74 std::chrono::milliseconds cleanup_interval;
75 bool is_strong_period;
76 std::optional<std::uint64_t> failed_updates_before_expiration;
77
78 FirstUpdateMode first_update_mode;
79 FirstUpdateType first_update_type;
80
81 std::chrono::milliseconds update_interval;
82 std::chrono::milliseconds update_jitter;
83 std::chrono::milliseconds full_update_interval;
84 std::chrono::milliseconds full_update_jitter;
85 std::optional<std::chrono::milliseconds> exception_interval;
86 bool updates_enabled;
87 std::uint64_t alert_on_failing_to_update_times;
88};
89
90extern const dynamic_config::Key<std::unordered_map<std::string, ConfigPatch>>
91 kCacheConfigSet;
92
93} // namespace cache
94
95USERVER_NAMESPACE_END