#include <userver/cache/base_mongo_cache.hpp>
Base class for all caches polling mongo collection
You have to provide a traits class in order to use this.
See components::CachingComponentBase
All options of CachingComponentBase and
Name | Description | Default value |
---|---|---|
update-correction | adjusts incremental updates window to overlap with previous update | 0 |
All fields below (except for function overrides) are mandatory.
Definition at line 122 of file base_mongo_cache.hpp.
Public Types | |
using | DataType |
Public Member Functions | |
MongoCache (const ComponentConfig &, const ComponentContext &) | |
utils::SharedReadablePtr< MongoCacheTraits::DataType > | Get () const |
utils::SharedReadablePtr< MongoCacheTraits::DataType > | GetUnsafe () const |
concurrent::AsyncEventSubscriberScope | UpdateAndListen (Class *obj, std::string name, void(Class::*func)(const std::shared_ptr< const MongoCacheTraits::DataType > &)) |
concurrent::AsyncEventChannel< const std::shared_ptr< const MongoCacheTraits::DataType > & > & | GetEventChannel () |
ComponentHealth | GetComponentHealth () const override |
void | OnLoadingCancelled () override |
void | OnAllComponentsAreStopping () override |
Static Public Member Functions | |
static yaml_config::Schema | GetStaticConfigSchema () |
Static Public Attributes | |
static constexpr std::string_view | kName = MongoCacheTraits::kName |
Protected Types | |
using | LoggableComponentBase = ComponentBase |
Legacy alias, use ComponentBase instead. | |
enum class | Flag { kNone = 0 , kNoFirstUpdate = 1 << 0 } |
Periodic update flags. More... | |
Protected Member Functions | |
void | Set (std::unique_ptr< const MongoCacheTraits::DataType > value_ptr) |
void | Set (MongoCacheTraits::DataType &&value) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | Emplace (Args &&... args) |
void | Clear () |
Clears the content of the cache by string a default constructed T. | |
virtual bool | MayReturnNull () const |
Whether Get is expected to return nullptr . | |
virtual void | PreAssignCheck (const MongoCacheTraits::DataType *old_value_ptr, const MongoCacheTraits::DataType *new_value_ptr) const |
If the option has-pre-assign-check is set true in static config, this function is called before assigning the new value to the cache. | |
void | InvalidateAsync (UpdateType update_type) |
Non-blocking forced cache update of specified type. | |
void | UpdateSyncDebug (UpdateType update_type) |
Forces a cache update of specified type. | |
const std::string & | Name () const |
AllowedUpdateTypes | GetAllowedUpdateTypes () const |
Update types configured for the cache. | |
void | StartPeriodicUpdates (utils::Flags< Flag > flags={}) |
Starts periodic updates. | |
void | StopPeriodicUpdates () |
Stops periodic updates. | |
void | AssertPeriodicUpdateStarted () |
void | AssertPeriodicUpdateStopped () |
void | OnCacheModified () |
virtual void | WriteContents (dump::Writer &writer, const MongoCacheTraits::DataType &contents) const |
virtual std::unique_ptr< const MongoCacheTraits::DataType > | ReadContents (dump::Reader &reader) const |
|
inherited |
Definition at line 162 of file caching_component_base.hpp.
|
protectedinherited |
Legacy alias, use ComponentBase instead.
Definition at line 67 of file component_base.hpp.
|
strongprotectedinherited |
Periodic update flags.
Enumerator | |
---|---|
kNoFirstUpdate | Disable initial update on start.
|
Definition at line 61 of file cache_update_trait.hpp.
components::MongoCache< MongoCacheTraits >::MongoCache | ( | const ComponentConfig & | config, |
const ComponentContext & | context ) |
Definition at line 163 of file base_mongo_cache.hpp.
components::MongoCache< MongoCacheTraits >::~MongoCache | ( | ) |
Definition at line 193 of file base_mongo_cache.hpp.
|
protectedinherited |
Clears the content of the cache by string a default constructed T.
Definition at line 199 of file caching_component_base.hpp.
|
protectedinherited |
Definition at line 196 of file caching_component_base.hpp.
|
inherited |
nullptr
if and only if MayReturnNull returns true
. cache::EmptyCacheError | if the contents are nullptr , and MayReturnNull returns false (which is the default behavior). |
Definition at line 168 of file caching_component_base.hpp.
|
inlineoverridevirtualinherited |
Override this function to inform the world of the state of your component.
Reimplemented from components::RawComponentBase.
Reimplemented in server::handlers::Restart.
Definition at line 35 of file component_base.hpp.
|
inherited |
Definition at line 179 of file caching_component_base.hpp.
|
static |
Definition at line 334 of file base_mongo_cache.hpp.
|
inherited |
Definition at line 171 of file caching_component_base.hpp.
|
inherited |
Non-blocking forced cache update of specified type.
|
protectedvirtualinherited |
Whether Get is expected to return nullptr
.
Definition at line 202 of file caching_component_base.hpp.
|
inherited |
|
inlineoverridevirtualinherited |
Component may use this function to stop doing work before the stop of the components that depend on it.
Base components may override it and make final
to do some work before the derived object constructor is called. Don't use it otherwise.
Reimplemented from components::RawComponentBase.
Reimplemented in urabbitmq::ConsumerComponentBase, and components::Server.
Definition at line 58 of file component_base.hpp.
|
protectedinherited |
Called in CachingComponentBase::Set
during update to indicate that the cached data has been modified
|
inlineoverridevirtualinherited |
Called once if the creation of any other component failed. If the current component expects some other component to take any action with the current component, this call is a signal that such action may never happen due to components loading was cancelled. Application components might not want to override it.
Reimplemented from components::RawComponentBase.
Definition at line 42 of file component_base.hpp.
|
protectedvirtualinherited |
If the option has-pre-assign-check is set true in static config, this function is called before assigning the new value to the cache.
Definition at line 214 of file caching_component_base.hpp.
|
protectedvirtualinherited |
Definition at line 208 of file caching_component_base.hpp.
|
protectedinherited |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 192 of file caching_component_base.hpp.
|
protectedinherited |
Sets the new value of cache. As a result the Get() member function starts returning the value passed into this function after the Update() finishes.
Definition at line 189 of file caching_component_base.hpp.
|
protectedinherited |
Stops periodic updates.
|
inherited |
Subscribes to cache updates using a member function. Also immediately invokes the function with the current cache contents.
Definition at line 177 of file caching_component_base.hpp.
|
inherited |
Forces a cache update of specified type.
If | Update throws |
|
protectedvirtualinherited |
Override to use custom serialization for cache dumps
Definition at line 206 of file caching_component_base.hpp.
|
staticconstexpr |
Definition at line 126 of file base_mongo_cache.hpp.