26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_REST_RESPONSE_CACHE_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_REST_RESPONSE_CACHE_H_
34#include <shared_mutex>
36#include <unordered_map>
43class EndpointResponseCache;
46 using TimeType = std::chrono::time_point<std::chrono::system_clock>;
78 void push(std::shared_ptr<CacheEntry>
entry);
106 const std::string &
key,
const std::string &data, int64_t items = 0,
107 std::optional<helper::MediaType> media_type = {},
108 std::optional<std::string> media_type_str = {});
114 std::shared_ptr<CacheEntry>
lookup(
const std::string &
key);
122 std::unordered_map<std::string, std::shared_ptr<CacheEntry>>
cache_;
132 const std::string &user_id,
133 const std::string &data,
137 const Uri &uri, std::string_view req_body,
const std::string &data,
138 std::optional<helper::MediaType> media_type = {});
141 const Uri &uri, std::string_view req_body,
const std::string &data,
142 const std::string &media_type_str);
145 const std::string &user_id);
148 std::string_view req_body);
152 bool ejected)
override;
161 const std::string &data,
168 bool ejected)
override;
Definition: response_cache.h:96
void remove_entry(std::shared_ptr< CacheEntry > entry, bool ejected)
Definition: response_cache.cc:242
std::shared_ptr< CacheEntry > lookup(const std::string &key)
Definition: response_cache.cc:256
std::shared_ptr< CacheEntry > create_entry(const std::string &key, const std::string &data, int64_t items=0, std::optional< helper::MediaType > media_type={}, std::optional< std::string > media_type_str={})
Definition: response_cache.cc:206
ResponseCache * owner_
Definition: response_cache.h:118
EndpointResponseCache(ResponseCache *owner, uint64_t ttl_ms)
Definition: response_cache.cc:200
std::chrono::milliseconds ttl_
Definition: response_cache.h:120
virtual void remove_entry_nolock(std::shared_ptr< CacheEntry > entry, bool ejected)
Definition: response_cache.cc:251
std::shared_mutex cache_mutex_
Definition: response_cache.h:123
std::unordered_map< std::string, std::shared_ptr< CacheEntry > > cache_
Definition: response_cache.h:122
::mrs::database::entry::UniversalId UniversalId
Definition: response_cache.h:99
virtual ~EndpointResponseCache()=default
Definition: response_cache.h:155
std::shared_ptr< CacheEntry > lookup_file(const UniversalId &id)
Definition: response_cache.cc:359
FileEndpointResponseCache(ResponseCache *owner)
Definition: response_cache.cc:356
std::shared_ptr< CacheEntry > create_file_entry(const UniversalId &id, const std::string &data, helper::MediaType media_type)
Definition: response_cache.cc:381
~FileEndpointResponseCache() override
Definition: response_cache.cc:369
void remove_entry_nolock(std::shared_ptr< CacheEntry > entry, bool ejected) override
Definition: response_cache.cc:392
Definition: response_cache.h:126
std::shared_ptr< CacheEntry > lookup_routine(const Uri &uri, std::string_view req_body)
Definition: response_cache.cc:338
ItemEndpointResponseCache(ResponseCache *owner, uint64_t ttl_ms)
Definition: response_cache.cc:278
void remove_entry_nolock(std::shared_ptr< CacheEntry > entry, bool ejected) override
Definition: response_cache.cc:348
std::shared_ptr< CacheEntry > create_table_entry(const Uri &uri, const std::string &user_id, const std::string &data, int64_t items)
Definition: response_cache.cc:294
std::shared_ptr< CacheEntry > create_routine_entry(const Uri &uri, std::string_view req_body, const std::string &data, std::optional< helper::MediaType > media_type={})
Definition: response_cache.cc:305
std::shared_ptr< CacheEntry > lookup_table(const Uri &uri, const std::string &user_id)
Definition: response_cache.cc:328
~ItemEndpointResponseCache() override
Definition: response_cache.cc:282
Definition: response_cache.h:64
void shrink_object_cache(size_t extra_size=0)
Definition: response_cache.cc:107
std::shared_ptr< CacheEntry > oldest_entry_
Definition: response_cache.h:89
std::string config_key_
Definition: response_cache.h:86
ResponseCache(const std::string &config_key)
Definition: response_cache.h:70
std::atomic< size_t > max_size_
Definition: response_cache.h:93
void configure(const std::string &options)
Definition: response_cache.cc:94
void remove_nolock(std::shared_ptr< CacheEntry > entry)
Definition: response_cache.cc:145
void remove(std::shared_ptr< CacheEntry > entry)
Definition: response_cache.cc:138
int remove_all(EndpointResponseCache *cache)
Definition: response_cache.cc:159
std::shared_ptr< CacheEntry > newest_entry_
Definition: response_cache.h:88
size_t max_cache_size() const
Definition: response_cache.h:75
void push(std::shared_ptr< CacheEntry > entry)
Definition: response_cache.cc:121
std::atomic< size_t > cache_size_
Definition: response_cache.h:91
std::mutex entries_mutex_
Definition: response_cache.h:90
MediaType
Definition: media_type.h:33
Request::Uri Uri
Definition: request.cc:36
std::chrono::milliseconds milliseconds
Definition: authorize_manager.cc:68
Definition: authorize_manager.h:48
constexpr const size_t k_default_object_cache_size
Definition: response_cache.h:62
mrs::database::entry::UniversalId UniversalId
Definition: universal_id.h:33
Definition: options.cc:57
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Definition: completion_hash.h:35
Definition: response_cache.h:45
std::string key
Definition: response_cache.h:53
std::chrono::time_point< std::chrono::system_clock > TimeType
Definition: response_cache.h:46
std::shared_ptr< CacheEntry > prev_ptr
Definition: response_cache.h:59
std::optional< std::string > media_type_str
Definition: response_cache.h:51
EndpointResponseCache * owner
Definition: response_cache.h:56
std::optional< helper::MediaType > media_type
Definition: response_cache.h:50
TimeType expiration_time
Definition: response_cache.h:54
int64_t items
Definition: response_cache.h:49
std::string data
Definition: response_cache.h:48
std::shared_ptr< CacheEntry > next_ptr
Definition: response_cache.h:58