Base class for caching components. More...
#include <userver/cache/caching_component_base.hpp>
Public Types | |
using | DataType = T |
Public Member Functions | |
CachingComponentBase (const ComponentConfig &config, const ComponentContext &) | |
utils::SharedReadablePtr< T > | Get () const |
utils::SharedReadablePtr< T > | GetUnsafe () const |
template<class Class > | |
concurrent::AsyncEventSubscriberScope | UpdateAndListen (Class *obj, std::string name, void(Class::*func)(const std::shared_ptr< const T > &)) |
concurrent::AsyncEventChannel< const std::shared_ptr< const T > & > & | GetEventChannel () |
![]() | |
LoggableComponentBase (const ComponentConfig &, const ComponentContext &) | |
LoggableComponentBase (LoggableComponentBase &&)=delete | |
LoggableComponentBase (const LoggableComponentBase &)=delete | |
~LoggableComponentBase () override=default | |
ComponentHealth | GetComponentHealth () const override |
void | OnLoadingCancelled () override |
void | OnAllComponentsLoaded () override |
void | OnAllComponentsAreStopping () override |
Static Public Member Functions | |
static yaml_config::Schema | GetStaticConfigSchema () |
![]() | |
static yaml_config::Schema | GetStaticConfigSchema () |
Protected Member Functions | |
void | Set (std::unique_ptr< const T > value_ptr) |
void | Set (T &&value) |
template<typename... Args> | |
void | Emplace (Args &&... args) |
void | Clear () |
virtual bool | MayReturnNull () const |
virtual void | WriteContents (dump::Writer &writer, const T &contents) const |
virtual std::unique_ptr< const T > | ReadContents (dump::Reader &reader) const |
![]() | |
AllowedUpdateTypes | GetAllowedUpdateTypes () const |
Update types configured for the cache. | |
void | StartPeriodicUpdates (utils::Flags< Flag > flags={}) |
Starts periodic updates. | |
void | StopPeriodicUpdates () |
Stops periodic updates. More... | |
void | AssertPeriodicUpdateStarted () |
void | OnCacheModified () |
virtual void | Update (UpdateType type, const std::chrono::system_clock::time_point &last_update, const std::chrono::system_clock::time_point &now, UpdateStatisticsScope &stats_scope)=0 |
Must override in a subclass. More... | |
CacheUpdateTrait (CacheUpdateTrait &&)=delete | |
CacheUpdateTrait & | operator= (CacheUpdateTrait &&)=delete |
void | Update (UpdateType update_type) |
Forces a cache update of specified type. More... | |
const std::string & | Name () const |
Additional Inherited Members | |
![]() | |
enum class | Flag { kNone = 0 , kNoFirstUpdate = 1 << 0 } |
Periodic update flags. More... | |
Base class for caching components.
Provides facilities for creating periodically updated caches. You need to override CacheUpdateTrait::Update then call CacheUpdateTrait::StartPeriodicUpdates after setup and CacheUpdateTrait::StopPeriodicUpdates before teardown.
Caching components must be configured in service config (see options below) and may be reconfigured dynamically via components::DynamicConfig.
Name | Description | Default value |
---|---|---|
update-types | specifies whether incremental and/or full updates will be used | see below |
update-interval | (required) interval between Update invocations | – |
update-jitter | max. amount of time by which interval may be adjusted for requests dispersal | update_interval / 10 |
full-update-interval | interval between full updates | – |
first-update-fail-ok | whether first update failure is non-fatal | false |
task-processor | the name of the TaskProcessor for running DoWork | main-task-processor |
config-settings | enables dynamic reconfiguration with CacheConfigSet | true |
additional-cleanup-interval | how often to run background RCU garbage collector | 10 seconds |
is-strong-period | whether to include Update execution time in update-interval | false |
testsuite-force-periodic-update | override testsuite-periodic-update-enabled in TestsuiteSupport component config | – |
full-and-incremental
: both update-interval
and full-update-interval
must be specified. Updates with UpdateType::kIncremental will be triggered each update-interval
(adjusted by jitter) unless full-update-interval
has passed and UpdateType::kFull is triggered.only-full
: only update-interval
must be specified. UpdateType::kFull will be triggered each update-interval
(adjusted by jitter).only-incremental
: only update-interval
must be specified. UpdateType::kFull is triggered on the first update, afterwards UpdateType::kIncremental will be triggered each update-interval
(adjusted by jitter).use it to enable periodic cache update for a component in testsuite environment where testsuite-periodic-update-enabled from TestsuiteSupport config is false
By default, update types are guessed based on update intervals presence. If both update-interval
and full-update-interval
are present, full-and-incremental
types is assumed. Otherwise only-full
is used.
dump::Dumper
for more info on persistent cache dumps and corresponding config options. Definition at line 86 of file caching_component_base.hpp.
using components::CachingComponentBase< T >::DataType = T |
Definition at line 94 of file caching_component_base.hpp.
components::CachingComponentBase< T >::CachingComponentBase | ( | const ComponentConfig & | config, |
const ComponentContext & | context | ||
) |
Definition at line 150 of file caching_component_base.hpp.
|
override |
Definition at line 159 of file caching_component_base.hpp.
|
protected |
Definition at line 233 of file caching_component_base.hpp.
|
protected |
Definition at line 228 of file caching_component_base.hpp.
utils::SharedReadablePtr< T > components::CachingComponentBase< T >::Get |
Definition at line 168 of file caching_component_base.hpp.
concurrent::AsyncEventChannel< const std::shared_ptr< const T > & > & components::CachingComponentBase< T >::GetEventChannel |
Definition at line 189 of file caching_component_base.hpp.
|
static |
Definition at line 292 of file caching_component_base.hpp.
utils::SharedReadablePtr< T > components::CachingComponentBase< T >::GetUnsafe |
Definition at line 194 of file caching_component_base.hpp.
|
protectedvirtual |
Whether Get() is expected to return nullptr. If MayReturnNull() returns false, Get() throws an exception instead of returning nullptr.
Definition at line 238 of file caching_component_base.hpp.
|
protectedvirtual |
Definition at line 265 of file caching_component_base.hpp.
|
protected |
Definition at line 199 of file caching_component_base.hpp.
|
protected |
Definition at line 222 of file caching_component_base.hpp.
concurrent::AsyncEventSubscriberScope components::CachingComponentBase< T >::UpdateAndListen | ( | Class * | obj, |
std::string | name, | ||
void(Class::*)(const std::shared_ptr< const T > &) | func | ||
) |
Subscribes to cache updates using a member function. Also immediately invokes the function with the current cache contents.
Definition at line 178 of file caching_component_base.hpp.
|
protectedvirtual |
Override to use custom serialization for cache dumps
Definition at line 255 of file caching_component_base.hpp.