userver: components::PostgreCache< PostgreCachePolicy > Class Template Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
components::PostgreCache< PostgreCachePolicy > Class Template Referencefinal

#include <userver/cache/base_postgres_cache.hpp>

Detailed Description

template<typename PostgreCachePolicy>
class components::PostgreCache< PostgreCachePolicy >

Caching component for PostgreSQL. See Caching Component for PostgreSQL.

See also
Caching Component for PostgreSQL, Basics of Caches
Examples
samples/postgres_auth/user_info_cache.hpp.

Definition at line 395 of file base_postgres_cache.hpp.

+ Inheritance diagram for components::PostgreCache< PostgreCachePolicy >:

Public Types

using PolicyType = PostgreCachePolicy
 
using ValueType = pg_cache::detail::ValueType<PolicyType>
 
using RawValueType = pg_cache::detail::RawValueType<PolicyType>
 
using DataType = pg_cache::detail::DataCacheContainerType<PolicyType>
 
using PolicyCheckerType = pg_cache::detail::PolicyChecker<PostgreCachePolicy>
 
using UpdatedFieldType = pg_cache::detail::UpdatedFieldType<PostgreCachePolicy>
 
using BaseType = typename PolicyCheckerType::BaseType
 

Public Member Functions

 PostgreCache (const ComponentConfig &, const ComponentContext &)
 
utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > Get () const
 
utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > Get () const
 
utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > GetUnsafe () const
 
utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > GetUnsafe () const
 
concurrent::AsyncEventSubscriberScope UpdateAndListen (Class *obj, std::string name, void(Class::*func)(const std::shared_ptr< const DataCacheContainerType< PostgreCachePolicy > > &))
 
concurrent::AsyncEventSubscriberScope UpdateAndListen (Class *obj, std::string name, void(Class::*func)(const std::shared_ptr< const DataCacheContainerType< PostgreCachePolicy > > &))
 
concurrent::AsyncEventChannel< const std::shared_ptr< const DataCacheContainerType< PostgreCachePolicy > > & > & GetEventChannel ()
 
concurrent::AsyncEventChannel< const std::shared_ptr< const DataCacheContainerType< PostgreCachePolicy > > & > & GetEventChannel ()
 
const std::string & Name () const
 
const std::string & Name () const
 
void InvalidateAsync (UpdateType update_type)
 Non-blocking forced cache update of specified type.
 
void InvalidateAsync (UpdateType update_type)
 Non-blocking forced cache update of specified type.
 
void InvalidateAsync (UpdateType update_type)
 Non-blocking forced cache update of specified type.
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsAreStopping () override
 
void UpdateSyncDebug (UpdateType update_type)
 Forces a cache update of specified type.
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

static constexpr bool kIncrementalUpdates = pg_cache::detail::kWantIncrementalUpdates<PolicyType>
 
static constexpr auto kClusterHostTypeFlags = pg_cache::detail::ClusterHostType<PolicyType>()
 
static constexpr auto kName = PolicyType::kName
 

Protected Types

using LoggableComponentBase
 
enum  Flag
 Periodic update flags. More...
 

Protected Member Functions

void Set (std::unique_ptr< const DataCacheContainerType< PostgreCachePolicy > > value_ptr)
 
void Set (DataCacheContainerType< PostgreCachePolicy > &&value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void Set (std::unique_ptr< const DataCacheContainerType< PostgreCachePolicy > > value_ptr)
 
void Set (DataCacheContainerType< PostgreCachePolicy > &&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 Emplace (Args &&... args)
 
void Clear ()
 Clears the content of the cache by string a default constructed T.
 
void Clear ()
 Clears the content of the cache by string a default constructed T.
 
virtual void PreAssignCheck (const DataCacheContainerType< PostgreCachePolicy > *old_value_ptr, const DataCacheContainerType< PostgreCachePolicy > *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.
 
virtual void PreAssignCheck (const DataCacheContainerType< PostgreCachePolicy > *old_value_ptr, const DataCacheContainerType< PostgreCachePolicy > *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 DataCacheContainerType< PostgreCachePolicy > &contents) const
 
virtual void WriteContents (dump::Writer &writer, const DataCacheContainerType< PostgreCachePolicy > &contents) const
 
virtual std::unique_ptr< const DataCacheContainerType< PostgreCachePolicy > > ReadContents (dump::Reader &reader) const
 
virtual std::unique_ptr< const DataCacheContainerType< PostgreCachePolicy > > ReadContents (dump::Reader &reader) const
 

Member Typedef Documentation

◆ BaseType

template<typename PostgreCachePolicy>
using components::PostgreCache< PostgreCachePolicy >::BaseType = typename PolicyCheckerType::BaseType

Definition at line 404 of file base_postgres_cache.hpp.

◆ DataType

template<typename PostgreCachePolicy>
using components::PostgreCache< PostgreCachePolicy >::DataType = pg_cache::detail::DataCacheContainerType<PolicyType>

Definition at line 401 of file base_postgres_cache.hpp.

◆ LoggableComponentBase

Deprecated
use components::ComponentBase instead.

Definition at line 67 of file component_base.hpp.

◆ PolicyCheckerType

template<typename PostgreCachePolicy>
using components::PostgreCache< PostgreCachePolicy >::PolicyCheckerType = pg_cache::detail::PolicyChecker<PostgreCachePolicy>

Definition at line 402 of file base_postgres_cache.hpp.

◆ PolicyType

template<typename PostgreCachePolicy>
using components::PostgreCache< PostgreCachePolicy >::PolicyType = PostgreCachePolicy

Definition at line 398 of file base_postgres_cache.hpp.

◆ RawValueType

template<typename PostgreCachePolicy>
using components::PostgreCache< PostgreCachePolicy >::RawValueType = pg_cache::detail::RawValueType<PolicyType>

Definition at line 400 of file base_postgres_cache.hpp.

◆ UpdatedFieldType

template<typename PostgreCachePolicy>
using components::PostgreCache< PostgreCachePolicy >::UpdatedFieldType = pg_cache::detail::UpdatedFieldType<PostgreCachePolicy>

Definition at line 403 of file base_postgres_cache.hpp.

◆ ValueType

template<typename PostgreCachePolicy>
using components::PostgreCache< PostgreCachePolicy >::ValueType = pg_cache::detail::ValueType<PolicyType>

Definition at line 399 of file base_postgres_cache.hpp.

Member Enumeration Documentation

◆ Flag

enum cache::CacheUpdateTrait::Flag
strongprotectedinherited

Periodic update flags.

Definition at line 61 of file cache_update_trait.hpp.

Constructor & Destructor Documentation

◆ PostgreCache()

template<typename PostgreCachePolicy>
components::PostgreCache< PostgreCachePolicy >::PostgreCache ( const ComponentConfig & config,
const ComponentContext & context )

Definition at line 460 of file base_postgres_cache.hpp.

◆ ~PostgreCache()

template<typename PostgreCachePolicy>
components::PostgreCache< PostgreCachePolicy >::~PostgreCache ( )
override

Definition at line 508 of file base_postgres_cache.hpp.

Member Function Documentation

◆ Clear()

void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::Clear ( )
protectedinherited

Clears the content of the cache by string a default constructed T.

Definition at line 199 of file caching_component_base.hpp.

◆ Emplace()

void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::Emplace ( Args &&... args)
protectedinherited

Definition at line 196 of file caching_component_base.hpp.

◆ Get() [1/2]

utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::Get ( ) const
inherited
Returns
cache contents. May be nullptr if and only if MayReturnNull returns true.
Exceptions
cache::EmptyCacheErrorif the contents are nullptr, and MayReturnNull returns false (which is the default behavior).

◆ Get() [2/2]

utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::Get ( ) const
inherited
Returns
cache contents. May be nullptr if and only if MayReturnNull returns true.
Exceptions
cache::EmptyCacheErrorif the contents are nullptr, and MayReturnNull returns false (which is the default behavior).

Definition at line 168 of file caching_component_base.hpp.

◆ GetComponentHealth()

ComponentHealth components::ComponentBase::GetComponentHealth ( ) const
inlineoverrideinherited

Override this function to inform the world of the state of your component.

Warning
The function is called concurrently from multiple threads.

Definition at line 35 of file component_base.hpp.

◆ GetEventChannel()

concurrent::AsyncEventChannel< const std::shared_ptr< const DataCacheContainerType< PostgreCachePolicy > > & > & components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::GetEventChannel ( )
inherited

Definition at line 179 of file caching_component_base.hpp.

◆ GetStaticConfigSchema()

template<typename PostgreCachePolicy>
yaml_config::Schema components::PostgreCache< PostgreCachePolicy >::GetStaticConfigSchema ( )
static

Definition at line 731 of file base_postgres_cache.hpp.

◆ GetUnsafe() [1/2]

utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::GetUnsafe ( ) const
inherited
Returns
cache contents. May be nullptr regardless of MayReturnNull.

◆ GetUnsafe() [2/2]

utils::SharedReadablePtr< DataCacheContainerType< PostgreCachePolicy > > components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::GetUnsafe ( ) const
inherited
Returns
cache contents. May be nullptr regardless of MayReturnNull.

Definition at line 171 of file caching_component_base.hpp.

◆ InvalidateAsync() [1/3]

void cache::CacheUpdateTrait::InvalidateAsync ( UpdateType update_type)
inherited

Non-blocking forced cache update of specified type.

See also
PeriodicTask::ForceStepAsync for behavior details

◆ InvalidateAsync() [2/3]

( UpdateType update_type)
inherited

Non-blocking forced cache update of specified type.

See also
PeriodicTask::ForceStepAsync for behavior details

◆ InvalidateAsync() [3/3]

void cache::CacheUpdateTrait::InvalidateAsync ( UpdateType update_type)
inherited

Non-blocking forced cache update of specified type.

See also
PeriodicTask::ForceStepAsync for behavior details

◆ Name() [1/2]

( ) const
inherited
Returns
name of the component

◆ Name() [2/2]

const std::string & cache::CacheUpdateTrait::Name ( ) const
inherited
Returns
name of the component

◆ OnAllComponentsAreStopping()

void components::ComponentBase::OnAllComponentsAreStopping ( )
inlineoverrideinherited

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.

Definition at line 58 of file component_base.hpp.

◆ OnCacheModified()

void cache::CacheUpdateTrait::OnCacheModified ( )
protectedinherited

Called in CachingComponentBase::Set during update to indicate that the cached data has been modified

◆ OnLoadingCancelled()

void components::ComponentBase::OnLoadingCancelled ( )
inlineoverrideinherited

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.

Definition at line 42 of file component_base.hpp.

◆ PreAssignCheck() [1/2]

virtual void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::PreAssignCheck ( const DataCacheContainerType< PostgreCachePolicy > * old_value_ptr,
const DataCacheContainerType< PostgreCachePolicy > * new_value_ptr ) const
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.

Note
old_value_ptr and new_value_ptr can be nullptr.

◆ PreAssignCheck() [2/2]

void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::PreAssignCheck ( const DataCacheContainerType< PostgreCachePolicy > * old_value_ptr,
const DataCacheContainerType< PostgreCachePolicy > * new_value_ptr ) const
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.

Note
old_value_ptr and new_value_ptr can be nullptr.

Definition at line 214 of file caching_component_base.hpp.

◆ ReadContents()

std::unique_ptr< const DataCacheContainerType< PostgreCachePolicy > > components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::ReadContents ( dump::Reader & reader) const
protectedvirtualinherited

Definition at line 208 of file caching_component_base.hpp.

◆ Set() [1/3]

void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::Set ( DataCacheContainerType< PostgreCachePolicy > && value)
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.

◆ Set() [2/3]

void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::Set ( std::unique_ptr< const DataCacheContainerType< PostgreCachePolicy > > value_ptr)
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.

Warning
Do not forget to update cache::UpdateStatisticsScope, otherwise the behavior is undefined.

◆ Set() [3/3]

void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::Set ( std::unique_ptr< const DataCacheContainerType< PostgreCachePolicy > > value_ptr)
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.

Warning
Do not forget to update cache::UpdateStatisticsScope, otherwise the behavior is undefined.

Definition at line 189 of file caching_component_base.hpp.

◆ StopPeriodicUpdates()

void cache::CacheUpdateTrait::StopPeriodicUpdates ( )
protectedinherited

Stops periodic updates.

Warning
Should be called in destructor of derived class.

◆ UpdateAndListen() [1/2]

concurrent::AsyncEventSubscriberScope components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::UpdateAndListen ( Class * obj,
std::string name,
void(Class::* func )(const std::shared_ptr< const DataCacheContainerType< PostgreCachePolicy > > &) )
inherited

Subscribes to cache updates using a member function. Also immediately invokes the function with the current cache contents.

◆ UpdateAndListen() [2/2]

concurrent::AsyncEventSubscriberScope components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::UpdateAndListen ( Class * obj,
std::string name,
void(Class::* func )(const std::shared_ptr< const DataCacheContainerType< PostgreCachePolicy > > &) )
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.

◆ UpdateSyncDebug() [1/2]

void cache::CacheUpdateTrait::UpdateSyncDebug ( UpdateType update_type)
inherited

Forces a cache update of specified type.

Exceptions
IfUpdate throws

◆ UpdateSyncDebug() [2/2]

void cache::CacheUpdateTrait::UpdateSyncDebug ( UpdateType update_type)
inherited

Forces a cache update of specified type.

Exceptions
IfUpdate throws

◆ WriteContents() [1/2]

virtual void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::WriteContents ( dump::Writer & writer,
const DataCacheContainerType< PostgreCachePolicy > & contents ) const
protectedvirtualinherited

Override to use custom serialization for cache dumps

◆ WriteContents() [2/2]

void components::CachingComponentBase< DataCacheContainerType< PostgreCachePolicy > >::WriteContents ( dump::Writer & writer,
const DataCacheContainerType< PostgreCachePolicy > & contents ) const
protectedvirtualinherited

Override to use custom serialization for cache dumps

Definition at line 206 of file caching_component_base.hpp.

Member Data Documentation

◆ kClusterHostTypeFlags

template<typename PostgreCachePolicy>
auto components::PostgreCache< PostgreCachePolicy >::kClusterHostTypeFlags = pg_cache::detail::ClusterHostType<PolicyType>()
staticconstexpr

Definition at line 408 of file base_postgres_cache.hpp.

◆ kIncrementalUpdates

template<typename PostgreCachePolicy>
bool components::PostgreCache< PostgreCachePolicy >::kIncrementalUpdates = pg_cache::detail::kWantIncrementalUpdates<PolicyType>
staticconstexpr

Definition at line 407 of file base_postgres_cache.hpp.

◆ kName

template<typename PostgreCachePolicy>
auto components::PostgreCache< PostgreCachePolicy >::kName = PolicyType::kName
staticconstexpr

Definition at line 409 of file base_postgres_cache.hpp.


The documentation for this class was generated from the following file: