Go to the documentation of this file.
32 class PersistentStringCacheImpl;
74 typedef std::unique_ptr<PersistentStringCache>
UPtr;
147 static UPtr open(std::string
const& cache_path);
200 int64_t
size() const noexcept;
265 bool put(std::
string const& key,
266 std::
string const& value,
267 std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
295 bool put(std::
string const& key,
298 std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
315 bool put(std::
string const& key,
316 std::
string const& value,
317 std::
string const& metadata,
318 std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
345 bool put(std::
string const& key,
348 char const* metadata,
349 int64_t metadata_size,
350 std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
416 bool put_metadata(std::
string const& key, std::
string const& metadata);
442 bool put_metadata(std::
string const& key,
char const* metadata, int64_t
size);
484 void invalidate(std::vector<std::
string> const& keys);
495 template<typename It>
498 std::vector<std::string> keys;
501 keys.push_back(*begin++);
512 void invalidate(std::initializer_list<std::string>
const& keys);
537 std::string
const& key,
538 std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
570 void trim_to(int64_t used_size_in_bytes);
645 std::unique_ptr<internal::PersistentStringCacheImpl> p_;
bool put(std::string const &key, std::string const &value, std::chrono::time_point< std::chrono::system_clock > expiry_time=std::chrono::system_clock::time_point())
Adds or updates an entry.
std::function< void(std::string const &key, PersistentStringCache &cache)> Loader
Function called by the cache to load an entry after a cache miss.
Definition: persistent_string_cache.h:355
Optional< Data > take_data(std::string const &key)
Removes an entry and returns its value and metadata.
bool contains_key(std::string const &key) const
Tests if an (unexpired) entry is in the cache.
Optional< std::string > get(std::string const &key) const
Returns the value of an entry in the cache, provided the entry has not expired.
CacheDiscardPolicy
Indicates the discard policy to make room for entries when the cache is full.
Definition: cache_discard_policy.h:35
PersistentCacheStats stats() const
Returns statistics for the cache.
Optional< std::string > take(std::string const &key)
Removes an entry and returns its value.
void resize(int64_t size_in_bytes)
Changes the maximum size of the cache.
Class that provides (read-only) access to cache statistics and settings.
Definition: persistent_cache_stats.h:42
boost::optional< T > Optional
Convenience typedef for nullable values.
Definition: optional.h:33
int64_t max_size_in_bytes() const noexcept
Returns the maximum size of the cache in bytes.
Optional< std::string > get_metadata(std::string const &key) const
Returns the metadata for an entry in the cache, provided the entry has not expired.
int64_t disk_size_in_bytes() const
Returns an estimate of the disk space consumed by the cache.
int64_t size() const noexcept
Returns the number of entries in the cache.
Simple pair of value and metadata.
Definition: persistent_string_cache.h:79
void clear_stats()
Resets all statistics counters.
Optional< Data > get_or_put_data(std::string const &key, Loader const &load_func)
Atomically retrieves or stores a cache entry.
Optional< std::string > get_or_put(std::string const &key, Loader const &load_func)
Atomically retrieves or stores a cache entry.
std::function< void(std::string const &key, CacheEvent ev, PersistentCacheStats const &stats)> EventCallback
The type of a handler function.
Definition: persistent_string_cache.h:612
std::unique_ptr< PersistentStringCache > UPtr
Definition: persistent_string_cache.h:74
PersistentStringCache & operator=(PersistentStringCache const &)=delete
Top-level namespace for core functionality.
Definition: cache_codec.h:23
PersistentStringCache(PersistentStringCache const &)=delete
A cache of key-value pairs with persistent storage.
Definition: persistent_string_cache.h:68
static UPtr open(std::string const &cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy)
Creates or opens a PersistentStringCache.
void trim_to(int64_t used_size_in_bytes)
Expires entries.
void compact()
Compacts the database.
bool touch(std::string const &key, std::chrono::time_point< std::chrono::system_clock > expiry_time=std::chrono::system_clock::time_point())
Updates the access time of an entry.
void set_handler(CacheEvent events, EventCallback cb)
Installs a handler for one or more events.
std::string metadata
Stores the metadata of an entry. If no metadata exists for an entry, metadata is returned as the empt...
Definition: persistent_string_cache.h:90
std::string value
Stores the value of an entry.
Definition: persistent_string_cache.h:84
void invalidate()
Deletes all entries from the cache.
Optional< Data > get_data(std::string const &key) const
Returns the data for an entry in the cache, provided the entry has not expired.
int64_t size_in_bytes() const noexcept
Returns the number of bytes consumed by entries in the cache.
CacheDiscardPolicy discard_policy() const noexcept
Returns the discard policy of the cache.
CacheEvent
Event types that can be monitored.
Definition: cache_events.h:38
bool put_metadata(std::string const &key, std::string const &metadata)
Adds or replaces the metadata for an entry.