29#include <olp/core/CoreApi.h>
30#include <olp/core/client/ApiError.h>
31#include <olp/core/client/ApiNoResult.h>
32#include <olp/core/client/ApiResponse.h>
33#include <olp/core/porting/any.h>
39using Encoder = std::function<std::string()>;
40using Decoder = std::function<olp::porting::any(
const std::string&)>;
42template <
typename Result>
43using OperationOutcome = client::ApiResponse<Result, client::ApiError>;
44using OperationOutcomeEmpty = OperationOutcome<client::ApiNoResult>;
54 static constexpr time_t kDefaultExpiry = std::numeric_limits<time_t>::max();
77 virtual bool Put(
const std::string& key,
const olp::porting::any& value,
78 const Encoder& encoder, time_t expiry = kDefaultExpiry) = 0;
90 time_t expiry = kDefaultExpiry) = 0;
100 virtual olp::porting::any
Get(
const std::string& key,
101 const Decoder& encoder) = 0;
119 virtual bool Remove(
const std::string& key) = 0;
138 virtual bool Contains(
const std::string& key)
const {
217 time_t expiry = kDefaultExpiry) {
258 const std::string& prefix) {
Contains utilities used to work around compiler warnings.
#define OLP_SDK_CORE_UNUSED(...)
Arbitrarily marks many variables as unused to avoid compiler warnings.
Definition WarningWorkarounds.h:28
An interface for a cache that expects a key-value pair.
Definition KeyValueCache.h:47
std::vector< unsigned char > ValueType
The value type that is stored in the DB.
Definition KeyValueCache.h:57
virtual ValueTypePtr Get(const std::string &key)=0
Gets the key and binary data from the cache.
virtual OperationOutcome< ValueTypePtr > Read(const std::string &key)
Gets the binary data from the cache.
Definition KeyValueCache.h:201
std::shared_ptr< ValueType > ValueTypePtr
The shared pointer type of the DB entry.
Definition KeyValueCache.h:60
virtual bool Put(const std::string &key, const ValueTypePtr value, time_t expiry=kDefaultExpiry)=0
Stores the raw binary data as a value in the cache.
virtual bool Remove(const std::string &key)=0
Removes the key-value pair from the cache.
virtual void Promote(const std::string &key)
Promotes a key in the cache LRU when applicable.
Definition KeyValueCache.h:191
virtual bool Release(const KeyListType &keys)
Removes a list of keys from protection.
Definition KeyValueCache.h:168
virtual OperationOutcomeEmpty Delete(const std::string &key)
Removes the key-value pair from the cache.
Definition KeyValueCache.h:231
virtual bool Put(const std::string &key, const olp::porting::any &value, const Encoder &encoder, time_t expiry=kDefaultExpiry)=0
Stores the key-value pair in the cache.
virtual OperationOutcomeEmpty Write(const std::string &key, const ValueTypePtr &value, time_t expiry=kDefaultExpiry)
Stores the raw binary data as a value in the cache.
Definition KeyValueCache.h:215
virtual OperationOutcomeEmpty DeleteByPrefix(const std::string &prefix)
Removes the values with the keys that match the given prefix from the cache.
Definition KeyValueCache.h:244
virtual bool Contains(const std::string &key) const
Checks if the key is in the cache.
Definition KeyValueCache.h:138
virtual OperationOutcome< KeyListType > ListKeysWithPrefix(const std::string &prefix)
Lists the keys that match the given prefix.
Definition KeyValueCache.h:257
virtual bool RemoveKeysWithPrefix(const std::string &prefix)=0
Removes the values with the keys that match the given prefix from the cache.
virtual bool IsProtected(const std::string &key) const
Checks if key is protected.
Definition KeyValueCache.h:181
virtual olp::porting::any Get(const std::string &key, const Decoder &encoder)=0
Gets the key-value pair from the cache.
virtual bool Protect(const KeyListType &keys)
Protects keys from eviction.
Definition KeyValueCache.h:153
std::vector< std::string > KeyListType
An alias for the list of keys to be protected or released.
Definition KeyValueCache.h:63
A wrapper around an internal error or HTTP status code.
Definition ApiError.h:37
Represents a request outcome.
Definition ApiResponse.h:65
Rules all the other namespaces.
Definition AppleSignInProperties.h:24