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>;
 
   82  void push(std::shared_ptr<CacheEntry> 
entry);
 
  109      const std::string &
key, 
const std::string &data, int64_t items = 0,
 
  110      std::optional<helper::MediaType> media_type = {},
 
  111      std::optional<std::string> media_type_str = {});
 
  117  std::shared_ptr<CacheEntry> 
lookup(
const std::string &
key) 
const;
 
  125  std::unordered_map<std::string, std::shared_ptr<CacheEntry>> 
cache_;
 
  135                                                 const std::string &user_id,
 
  136                                                 const std::string &data,
 
  140      const Uri &uri, std::string_view req_body, 
const std::string &data,
 
  141      std::optional<helper::MediaType> media_type = {});
 
  144      const Uri &uri, std::string_view req_body, 
const std::string &data,
 
  145      const std::string &media_type_str);
 
  148                                           const std::string &user_id);
 
  151                                             std::string_view req_body);
 
  155                           bool ejected) 
override;
 
  164                                                const std::string &data,
 
  171                           bool ejected) 
override;
 
Definition: response_cache.h:99
 
void remove_entry(std::shared_ptr< CacheEntry > entry, bool ejected)
Definition: response_cache.cc:234
 
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:202
 
ResponseCache * owner_
Definition: response_cache.h:121
 
EndpointResponseCache(ResponseCache *owner, uint64_t ttl_ms)
Definition: response_cache.cc:196
 
std::shared_ptr< CacheEntry > lookup(const std::string &key) const
Definition: response_cache.cc:247
 
std::chrono::milliseconds ttl_
Definition: response_cache.h:123
 
virtual void remove_entry_nolock(std::shared_ptr< CacheEntry > entry, bool ejected)
Definition: response_cache.cc:242
 
std::shared_mutex cache_mutex_
Definition: response_cache.h:126
 
std::unordered_map< std::string, std::shared_ptr< CacheEntry > > cache_
Definition: response_cache.h:125
 
::mrs::database::entry::UniversalId UniversalId
Definition: response_cache.h:102
 
virtual ~EndpointResponseCache()=default
 
Definition: response_cache.h:158
 
std::shared_ptr< CacheEntry > lookup_file(const UniversalId &id)
Definition: response_cache.cc:348
 
FileEndpointResponseCache(ResponseCache *owner)
Definition: response_cache.cc:345
 
std::shared_ptr< CacheEntry > create_file_entry(const UniversalId &id, const std::string &data, helper::MediaType media_type)
Definition: response_cache.cc:374
 
~FileEndpointResponseCache() override
Definition: response_cache.cc:364
 
void remove_entry_nolock(std::shared_ptr< CacheEntry > entry, bool ejected) override
Definition: response_cache.cc:385
 
Definition: response_cache.h:129
 
std::shared_ptr< CacheEntry > lookup_routine(const Uri &uri, std::string_view req_body)
Definition: response_cache.cc:322
 
ItemEndpointResponseCache(ResponseCache *owner, uint64_t ttl_ms)
Definition: response_cache.cc:259
 
void remove_entry_nolock(std::shared_ptr< CacheEntry > entry, bool ejected) override
Definition: response_cache.cc:337
 
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:273
 
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:284
 
std::shared_ptr< CacheEntry > lookup_table(const Uri &uri, const std::string &user_id)
Definition: response_cache.cc:307
 
~ItemEndpointResponseCache() override
Definition: response_cache.cc:263
 
Definition: response_cache.h:66
 
void shrink_object_cache(size_t extra_size=0)
Definition: response_cache.cc:106
 
std::shared_ptr< CacheEntry > oldest_entry_
Definition: response_cache.h:92
 
std::string config_key_
Definition: response_cache.h:89
 
ResponseCache(const std::string &config_key)
Definition: response_cache.h:72
 
std::atomic< size_t > max_size_
Definition: response_cache.h:96
 
void configure(const std::string &options)
Definition: response_cache.cc:94
 
void remove_nolock(std::shared_ptr< CacheEntry > entry)
Definition: response_cache.cc:142
 
void remove(std::shared_ptr< CacheEntry > entry)
Definition: response_cache.cc:132
 
int remove_all(EndpointResponseCache *cache)
Definition: response_cache.cc:156
 
std::shared_ptr< CacheEntry > newest_entry_
Definition: response_cache.h:91
 
size_t max_cache_size() const
Definition: response_cache.h:77
 
void push(std::shared_ptr< CacheEntry > entry)
Definition: response_cache.cc:116
 
std::atomic< size_t > cache_size_
Definition: response_cache.h:94
 
std::mutex entries_mutex_
Definition: response_cache.h:93
 
MediaType
Definition: media_type.h:33
 
Request::Uri Uri
Definition: request.cc:36
 
std::chrono::milliseconds milliseconds
Definition: authorize_manager.cc:67
 
Definition: authorize_manager.h:48
 
constexpr const size_t k_default_object_cache_size
Definition: response_cache.h:64
 
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
 
bool is_expired() const
Definition: response_cache.h:61
 
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