userver: userver/cache/cache_update_trait.hpp Source File
Loading...
Searching...
No Matches
cache_update_trait.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <memory>
7#include <string>
8
12#include <userver/dump/fwd.hpp>
14#include <userver/rcu/fwd.hpp>
16
17USERVER_NAMESPACE_BEGIN
18
19namespace cache {
20
21struct CacheDependencies;
22struct Config;
23
30class CacheUpdateTrait {
31public:
32 CacheUpdateTrait(CacheUpdateTrait&&) = delete;
33 CacheUpdateTrait& operator=(CacheUpdateTrait&&) = delete;
34
37 void InvalidateAsync(UpdateType update_type);
38
69 void UpdateSyncDebug(UpdateType update_type);
70
72 const std::string& Name() const noexcept;
73
74protected:
76 // For internal use only
77 CacheUpdateTrait(const components::ComponentConfig& config, const components::ComponentContext& context);
78
79 // For internal use only
80 explicit CacheUpdateTrait(CacheDependencies&& dependencies);
81
82 virtual ~CacheUpdateTrait();
84
87
89 enum class Flag {
90 kNone = 0,
91
95 };
96
99 void OnCacheModified() noexcept;
100
102 // For internal use only
103 rcu::ReadablePtr<Config> GetConfig() const;
104
105 // Checks for the presence of the flag for pre-assign check.
106 // For internal use only.
107 bool HasPreAssignCheck() const noexcept;
108
109 // Returns value of the flag safe-data-lifetime.
110 // For internal use only.
111 bool IsSafeDataLifetime() const noexcept;
112
113 // For internal use only.
114 void SetDataSizeStatistic(std::size_t size) noexcept;
115
116 // For internal use only
117 // TODO remove after TAXICOMMON-3959
118 engine::TaskProcessor& GetCacheTaskProcessor() const noexcept;
120
158 virtual void Update(
159 UpdateType type,
160 const std::chrono::system_clock::time_point& last_update,
161 const std::chrono::system_clock::time_point& now,
162 UpdateStatisticsScope& stats_scope
163 ) = 0;
164
166 virtual utils::Flags<Flag> GetStartFlags() const;
167
171
173 // For internal use only
174 void EarlyStopPeriodicUpdates();
176
177private:
178 void StartPeriodicUpdates();
179
180 void StopPeriodicUpdates();
181
182 virtual void Cleanup() = 0;
183
184 virtual void MarkAsExpired();
185
186 virtual void GetAndWrite(dump::Writer& writer) const;
187
188 virtual void ReadAndSet(dump::Reader& reader);
189
190 class Impl;
191 std::unique_ptr<Impl> impl_;
192};
193
194} // namespace cache
195
196USERVER_NAMESPACE_END