Your opinion will help to improve our service
Leave a feedback >#include <userver/cache/lru_cache_component_base.hpp>
Base class for LRU-cache components.
Provides facilities for creating LRU caches. You need to override LruCacheComponent::DoGetByKey to handle cache misses.
Caching components must be configured in service config (see options below) and may be reconfigured dynamically via components::DynamicConfig.
Name | Description | Default value |
---|---|---|
size | max amount of items to store in cache | – |
ways | number of ways for associative cache | – |
lifetime | TTL for cache entries (0 is unlimited) | 0 |
background-update | enables asynchronous updates for expiring values | false |
config-settings | enables dynamic reconfiguration with CacheConfigSet | true |
Do not forget to add the component to component list:
example-cache:
size: 1
ways: 1
lifetime: 1s # 0 (unlimited) by default
config-settings: false # true by default
Definition at line 78 of file lru_cache_component_base.hpp.
Public Types | |
using | Cache = ExpirableLruCache<Key, Value, Hash, Equal> |
using | CacheWrapper = LruCacheWrapper<Key, Value, Hash, Equal> |
Public Member Functions | |
LruCacheComponent (const components::ComponentConfig &, const components::ComponentContext &) | |
CacheWrapper | GetCache () |
ComponentHealth | GetComponentHealth () const override |
void | OnLoadingCancelled () override |
void | OnAllComponentsLoaded () override |
void | OnAllComponentsAreStopping () override |
Static Public Member Functions | |
static yaml_config::Schema | GetStaticConfigSchema () |
Protected Types | |
using | LoggableComponentBase = ComponentBase |
Protected Member Functions | |
virtual Value | DoGetByKey (const Key &key)=0 |
std::shared_ptr< Cache > | GetCacheRaw () |
using cache::LruCacheComponent< Key, Value, Hash, Equal >::Cache = ExpirableLruCache<Key, Value, Hash, Equal> |
Definition at line 80 of file lru_cache_component_base.hpp.
using cache::LruCacheComponent< Key, Value, Hash, Equal >::CacheWrapper = LruCacheWrapper<Key, Value, Hash, Equal> |
Definition at line 81 of file lru_cache_component_base.hpp.
|
protectedinherited |
Definition at line 67 of file component_base.hpp.
cache::LruCacheComponent< Key, Value, Hash, Equal >::LruCacheComponent | ( | const components::ComponentConfig & | config, |
const components::ComponentContext & | context ) |
Definition at line 123 of file lru_cache_component_base.hpp.
|
override |
Definition at line 160 of file lru_cache_component_base.hpp.
LruCacheComponent< Key, Value, Hash, Equal >::CacheWrapper cache::LruCacheComponent< Key, Value, Hash, Equal >::GetCache | ( | ) |
Definition at line 171 of file lru_cache_component_base.hpp.
|
inlineprotected |
Definition at line 94 of file lru_cache_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.
|
static |
Definition at line 206 of file lru_cache_component_base.hpp.
|
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 components::Server, and urabbitmq::ConsumerComponentBase.
Definition at line 58 of file component_base.hpp.
|
inlineoverridevirtualinherited |
Component may use this function to finalize registration of other components that depend on it (for example, handler components register in server component, and the latter uses OnAllComponentsLoaded() to start processing requests).
Base components may override it and make final
to do some work after the derived object constructor is called. Don't use it otherwise.
Reimplemented from components::RawComponentBase.
Reimplemented in components::Server, server::handlers::Ping, and urabbitmq::ConsumerComponentBase.
Definition at line 51 of file component_base.hpp.
|
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.