userver: components::PostgreCache< PostgreCachePolicy > Class Template Reference
Loading...
Searching...
No Matches
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 379 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
 
using BaseType = typename PolicyCheckerType::BaseType
 

Public Member Functions

 PostgreCache (const ComponentConfig &, 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 ()
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsAreStopping () override
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

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

Member Typedef Documentation

◆ BaseType

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

Definition at line 390 of file base_postgres_cache.hpp.

◆ DataType

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

Definition at line 386 of file base_postgres_cache.hpp.

◆ LoggableComponentBase

Legacy alias, use ComponentBase instead.

Definition at line 69 of file component_base.hpp.

◆ PolicyCheckerType

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

Definition at line 387 of file base_postgres_cache.hpp.

◆ PolicyType

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

Definition at line 383 of file base_postgres_cache.hpp.

◆ RawValueType

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

Definition at line 385 of file base_postgres_cache.hpp.

◆ UpdatedFieldType

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

Definition at line 388 of file base_postgres_cache.hpp.

◆ ValueType

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

Definition at line 384 of file base_postgres_cache.hpp.

Member Enumeration Documentation

◆ Flag

enum class cache::CacheUpdateTrait::Flag
strongprotectedinherited

Periodic update flags.

Enumerator
kNoFirstUpdate 

Disable initial update on start.

Definition at line 62 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 442 of file base_postgres_cache.hpp.

◆ ~PostgreCache()

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

Definition at line 494 of file base_postgres_cache.hpp.

Member Function Documentation

◆ Clear()

template<typename T >
void components::CachingComponentBase< T >::Clear ( )
protectedinherited

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

Definition at line 316 of file caching_component_base.hpp.

◆ Emplace()

template<typename T >
template<typename... Args>
void components::CachingComponentBase< T >::Emplace ( Args &&... args)
protectedinherited

Definition at line 311 of file caching_component_base.hpp.

◆ Get()

template<typename T >
utils::SharedReadablePtr< T > components::CachingComponentBase< T >::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 259 of file caching_component_base.hpp.

◆ GetComponentHealth()

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

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

Warning
The function is called concurrently from multiple threads.

Reimplemented from components::RawComponentBase.

Definition at line 35 of file component_base.hpp.

◆ GetEventChannel()

template<typename T >
concurrent::AsyncEventChannel< const std::shared_ptr< const T > & > & components::CachingComponentBase< T >::GetEventChannel ( )
inherited

Definition at line 280 of file caching_component_base.hpp.

◆ GetStaticConfigSchema()

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

Definition at line 706 of file base_postgres_cache.hpp.

◆ GetUnsafe()

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

Definition at line 285 of file caching_component_base.hpp.

◆ InvalidateAsync()

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

Non-blocking forced cache update of specified type.

See also
PeriodicTask::ForceStepAsync for behavior details

◆ Name()

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

◆ OnAllComponentsAreStopping()

void components::ComponentBase::OnAllComponentsAreStopping ( )
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 60 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 ( )
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 44 of file component_base.hpp.

◆ PreAssignCheck()

template<typename T >
void components::CachingComponentBase< T >::PreAssignCheck ( const T * old_value_ptr,
const T * 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 403 of file caching_component_base.hpp.

◆ ReadContents()

template<typename T >
std::unique_ptr< const T > components::CachingComponentBase< T >::ReadContents ( dump::Reader & reader) const
protectedvirtualinherited

Definition at line 354 of file caching_component_base.hpp.

◆ Set() [1/2]

template<typename T >
void components::CachingComponentBase< T >::Set ( std::unique_ptr< const T > 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 290 of file caching_component_base.hpp.

◆ Set() [2/2]

template<typename T >
void components::CachingComponentBase< T >::Set ( T && 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 305 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()

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

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

Definition at line 269 of file caching_component_base.hpp.

◆ UpdateSyncDebug()

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

Forces a cache update of specified type.

Exceptions
IfUpdate throws

◆ WriteContents()

template<typename T >
void components::CachingComponentBase< T >::WriteContents ( dump::Writer & writer,
const T & contents ) const
protectedvirtualinherited

Override to use custom serialization for cache dumps

Definition at line 344 of file caching_component_base.hpp.

Member Data Documentation

◆ kClusterHostTypeFlags

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

Definition at line 395 of file base_postgres_cache.hpp.

◆ kIncrementalUpdates

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

Definition at line 393 of file base_postgres_cache.hpp.

◆ kName

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

Definition at line 397 of file base_postgres_cache.hpp.


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