template<class MongoCacheTraits>
class components::MongoCache< MongoCacheTraits >
Base class for all caches polling mongo collection
You have to provide a traits class in order to use this.
For avoiding "memory leaks", see the respective section in components::CachingComponentBase.
Static options of components::MongoCache :
| Name | Description | Default value |
| update-correction | Adjusts incremental updates window to overlap with previous update. | 0 |
Options inherited from components::CachingComponentBase :
| Name | Description | Default value |
| update-types | Specifies whether incremental and/or full updates are used. Possible values: full-and-incremental, only-full, only-incremental. | – |
| update-interval | (required) interval between Update invocations. | – |
| update-jitter | Max. amount of time by which update-interval may be adjusted for requests dispersal. | update_interval / 10 |
| updates-enabled | If false, cache updates are disabled (except for the first one if !first-update-fail-ok). | true |
| full-update-interval | Interval between full updates. | – |
| full-update-jitter | Max. amount of time by which full-update-interval may be adjusted for requests dispersal. | full-update-interval / 10 |
| exception-interval | Sleep interval after an unhandled exception. | update_interval |
| 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 |
| has-pre-assign-check | Enables the check before changing the value in the cache, by default it is the check that the new value is not empty. | false |
| testsuite-force-periodic-update | Override testsuite-periodic-update-enabled in TestsuiteSupport component config. | – |
| failed-updates-before-expiration | The number of consecutive failed updates for data expiration. | – |
| alert-on-failing-to-update-times | Fire an alert if the cache update failed specified amount of times in a row. If zero - alerts are disabled. Value from dynamic config takes priority over static. | 0 |
| safe-data-lifetime | Enables awaiting data destructors in the component's destructor. Can be set to false if the stored data does not refer to the component and its dependencies. | true |
| dump | Manages cache behavior after dump load. | – |
| dump.first-update-mode | Behavior of update after successful load from dump. skip - after successful load from dump, do nothing; required - make a synchronous update of type first-update-type, stop the service on failure; best-effort - make a synchronous update of type first-update-type, keep working and use data from dump on failure. Possible values: skip, required, best-effort. | skip |
| dump.first-update-type | Update type after successful load from dump. Possible values: full, incremental, incremental-then-async-full. | full |
Options inherited from components::ComponentBase :
| Name | Description | Default value |
| load-enabled | Set to false to disable loading of the component. | true |
Traits example:
All fields below (except for function overrides) are mandatory.
struct MongoCacheTraitsExample {
static constexpr std::string_view kName = "mongo-dynamic-config";
static constexpr auto kMongoCollectionsField =
&storages::mongo::Collections::config;
static constexpr const std::string& kMongoUpdateFieldName =
mongo::db::taxi::config::kUpdated;
using ObjectType = CachedObject;
static constexpr auto kKeyField = &CachedObject::name;
using KeyType = std::string;
using DataType = std::unordered_map<KeyType, ObjectType>;
static constexpr bool kIsSecondaryPreferred = true;
static constexpr auto DeserializeObject = &CachedObject::FromBson;
return doc[
"value"].
As<ObjectType>();
}
static constexpr bool kUseDefaultDeserializeObject = true;
const std::chrono::system_clock::time_point& last_update,
const std::chrono::system_clock::time_point& now,
const std::chrono::system_clock::duration& correction) {
mongo::operations::Find find_op({});
find_op.SetOption(mongo::options::Projection{"key", "value"});
return find_op;
}
static constexpr bool kUseDefaultFindOperation = true;
static constexpr bool kAreInvalidDocumentsSkipped = false;
using MongoCollectionsComponent = components::MongoCollections;
};
Definition at line 121 of file base_mongo_cache.hpp.
|
| 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 | Attach (const std::shared_ptr< const MongoCacheTraits::DataType > &value_ptr) |
| |
| 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 | UpdateSyncDebug (UpdateType update_type) |
| | Forces a cache update of specified type.
|
| |
|
AllowedUpdateTypes | GetAllowedUpdateTypes () const |
| | Update types configured for the cache.
|
| |
|
void | StartPeriodicUpdates (utils::Flags< Flag > flags={}) |
| | Starts periodic updates.
|
| |
|
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 |
| |