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 {
23public:
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, formats::parse::To<FirstUpdateMode>);
34
35std::string_view ToString(FirstUpdateMode);
36
37enum class FirstUpdateType {
38 kFull,
39 kIncremental,
40 kIncrementalThenAsyncFull,
41};
42
43FirstUpdateType Parse(const yaml_config::YamlConfig& config, formats::parse::To<FirstUpdateType>);
44
45std::string_view ToString(FirstUpdateType);
46
47struct ConfigPatch final {
48 std::chrono::milliseconds update_interval{};
49 std::chrono::milliseconds update_jitter{};
50 std::chrono::milliseconds full_update_interval{};
51 std::chrono::milliseconds full_update_jitter{};
52 std::optional<std::chrono::milliseconds> exception_interval{};
53 bool updates_enabled{true};
54 std::uint64_t alert_on_failing_to_update_times{0};
55};
56
57ConfigPatch Parse(const formats::json::Value& value, formats::parse::To<ConfigPatch>);
58
59struct Config final {
60 Config() = default;
61 explicit Config(const yaml_config::YamlConfig& config, const std::optional<dump::Config>& dump_config);
62
63 Config MergeWith(const ConfigPatch& patch) const;
64
65 AllowedUpdateTypes allowed_update_types{};
66 bool allow_first_update_failure{};
67 std::optional<bool> force_periodic_update;
68 bool config_updates_enabled{};
69 bool has_pre_assign_check{};
70 std::optional<std::string> task_processor_name;
71 std::chrono::milliseconds cleanup_interval{};
72 bool is_strong_period{};
73 std::optional<std::uint64_t> failed_updates_before_expiration;
74 bool is_safe_data_lifetime{};
75
76 FirstUpdateMode first_update_mode{};
77 FirstUpdateType first_update_type{};
78
79 std::chrono::milliseconds update_interval{};
80 std::chrono::milliseconds update_jitter{};
81 std::chrono::milliseconds full_update_interval{};
82 std::chrono::milliseconds full_update_jitter{};
83 std::optional<std::chrono::milliseconds> exception_interval;
84 bool updates_enabled{};
85 std::uint64_t alert_on_failing_to_update_times{};
86};
87
88extern const dynamic_config::Key<std::unordered_map<std::string, ConfigPatch>> kCacheConfigSet;
89
90} // namespace cache
91
92USERVER_NAMESPACE_END