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>
34 #include <boost/any.hpp>
39 using Encoder = std::function<std::string()>;
40 using Decoder = std::function<boost::any(
const std::string&)>;
42 template <
typename Result>
43 using OperationOutcome = client::ApiResponse<Result, client::ApiError>;
44 using 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 boost::any& value,
78 const Encoder& encoder, time_t expiry = kDefaultExpiry) = 0;
90 time_t expiry = kDefaultExpiry) = 0;
100 virtual boost::any
Get(
const std::string& key,
const Decoder& encoder) = 0;
118 virtual bool Remove(
const std::string& key) = 0;
137 virtual bool Contains(
const std::string& key)
const {
216 time_t expiry = kDefaultExpiry) {
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.
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 boost::any &value, const Encoder &encoder, time_t expiry=kDefaultExpiry)=0
Stores the key-value pair in the cache.
virtual boost::any Get(const std::string &key, const Decoder &encoder)=0
Gets the key-value pair from the cache.
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:190
virtual bool Release(const KeyListType &keys)
Removes a list of keys from protection.
Definition: KeyValueCache.h:167
virtual OperationOutcomeEmpty Delete(const std::string &key)
Removes the key-value pair from the cache.
Definition: KeyValueCache.h:230
virtual OperationOutcome< ValueTypePtr > Read(const std::string &key)
Gets the binary data from the cache.
Definition: KeyValueCache.h:200
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:214
virtual OperationOutcomeEmpty DeleteByPrefix(const std::string &prefix)
Removes the values with the keys that match the given prefix from the cache.
Definition: KeyValueCache.h:243
virtual bool Contains(const std::string &key) const
Checks if the key is in the cache.
Definition: KeyValueCache.h:137
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:180
virtual bool Protect(const KeyListType &keys)
Protects keys from eviction.
Definition: KeyValueCache.h:152
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