userver: testsuite::CacheControl Class Reference
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
testsuite::CacheControl Class Referencefinal

#include <userver/testsuite/cache_control.hpp>

Detailed Description

Testsuite interface for caches and cache-like components.

If a component stores transient state that may be carried between tests, or stores caches that may become stale, then it should register its resetter here. Example:

class MyCache final : public components::LoggableComponentBase {
public:
static constexpr std::string_view kName = "my-component-default-name";
MyCache(const components::ComponentConfig& config,
: components::LoggableComponentBase(config, context) {
{
auto cache = cached_token_.Lock();
*cache = FetchToken();
}
// ...
// reset_registration_ must be set at the end of the constructor.
reset_registration_ =
testsuite::RegisterCache(config, context, this, &MyCache::ResetCache);
}
std::string GetToken() {
auto cache = cached_token_.Lock();
if (auto& opt_token = *cache; opt_token) return *opt_token;
auto new_token = FetchToken();
*cache = new_token;
return new_token;
}
void ReportServiceRejectedToken() { ResetCache(); }
private:
std::string FetchToken() const;
void ResetCache() {
auto cache = cached_token_.Lock();
cache->reset();
}
// Subscriptions must be the last fields.
testsuite::CacheResetRegistration reset_registration_;
};

Testsuite will then call this hook in the beginning of each test. You can also reset a specific cache in testsuite explicitly as follows:

service_client.invalidate_caches(names=['your-cache-name'])

CacheControl is normally acquired through testsuite::FindCacheControl.

All methods are coro-safe.

Definition at line 54 of file cache_control.hpp.

Public Member Functions

void ResetAllCaches (cache::UpdateType update_type, const std::unordered_set< std::string > &force_incremental_names, const std::unordered_set< std::string > &exclude_names)
 Reset all the registered caches.
 
void ResetCaches (cache::UpdateType update_type, std::unordered_set< std::string > reset_only_names, const std::unordered_set< std::string > &force_incremental_names)
 Reset caches with the specified names.
 
 CacheControl (CacheControl &&)=delete
 
CacheControloperator= (CacheControl &&)=delete
 

Member Function Documentation

◆ ResetAllCaches()

void testsuite::CacheControl::ResetAllCaches ( cache::UpdateType update_type,
const std::unordered_set< std::string > & force_incremental_names,
const std::unordered_set< std::string > & exclude_names )

Reset all the registered caches.

update_type is used by caches derived from component::CachingComponentBase.

◆ ResetCaches()

void testsuite::CacheControl::ResetCaches ( cache::UpdateType update_type,
std::unordered_set< std::string > reset_only_names,
const std::unordered_set< std::string > & force_incremental_names )

Reset caches with the specified names.

update_type is used by caches derived from component::CachingComponentBase.

Friends And Related Symbol Documentation

◆ CacheResetRegistration

friend class CacheResetRegistration
friend

Definition at line 105 of file cache_control.hpp.


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