An interface for a cache that expects a key-value pair.
More...
#include <KeyValueCache.h>
|
using | ValueType = std::vector< unsigned char > |
| The value type that is stored in the DB.
|
|
using | ValueTypePtr = std::shared_ptr< ValueType > |
| The shared pointer type of the DB entry.
|
|
using | KeyListType = std::vector< std::string > |
| An alias for the list of keys to be protected or released.
|
|
|
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. More...
|
|
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. More...
|
|
virtual boost::any | Get (const std::string &key, const Decoder &encoder)=0 |
| Gets the key-value pair from the cache. More...
|
|
virtual ValueTypePtr | Get (const std::string &key)=0 |
| Gets the key and binary data from the cache. More...
|
|
virtual bool | Remove (const std::string &key)=0 |
| Removes the key-value pair from the cache. More...
|
|
virtual bool | RemoveKeysWithPrefix (const std::string &prefix)=0 |
| Removes the values with the keys that match the given prefix from the cache. More...
|
|
virtual bool | Contains (const std::string &key) const |
| Checks if the key is in the cache. More...
|
|
virtual bool | Protect (const KeyListType &keys) |
| Protects keys from eviction. More...
|
|
virtual bool | Release (const KeyListType &keys) |
| Removes a list of keys from protection. More...
|
|
virtual bool | IsProtected (const std::string &key) const |
| Checks if key is protected. More...
|
|
virtual void | Promote (const std::string &key) |
| Promotes a key in the cache LRU when applicable. More...
|
|
|
static constexpr time_t | kDefaultExpiry = std::numeric_limits<time_t>::max() |
| The expiry time of the key-value pair. More...
|
|
An interface for a cache that expects a key-value pair.
◆ Contains()
virtual bool olp::cache::KeyValueCache::Contains |
( |
const std::string & |
key | ) |
const |
|
inlinevirtual |
Checks if the key is in the cache.
- Parameters
-
key | The key for the value. |
- Returns
- True if the key is cached; false otherwise.
Reimplemented in olp::cache::DefaultCache.
◆ Get() [1/2]
virtual ValueTypePtr olp::cache::KeyValueCache::Get |
( |
const std::string & |
key | ) |
|
|
pure virtual |
Gets the key and binary data from the cache.
- Parameters
-
key | The key that is used to look for the binary data. |
- Returns
- The key and binary data.
Implemented in olp::cache::DefaultCache.
◆ Get() [2/2]
virtual boost::any olp::cache::KeyValueCache::Get |
( |
const std::string & |
key, |
|
|
const Decoder & |
encoder |
|
) |
| |
|
pure virtual |
Gets the key-value pair from the cache.
- Parameters
-
key | The key that is used to look for the key-value pair. |
encoder | Decodes the value from a string. |
- Returns
- The key-value pair.
Implemented in olp::cache::DefaultCache.
◆ IsProtected()
virtual bool olp::cache::KeyValueCache::IsProtected |
( |
const std::string & |
key | ) |
const |
|
inlinevirtual |
Checks if key is protected.
- Parameters
-
- Returns
- True if the key are in the protected list; false otherwise.
Reimplemented in olp::cache::DefaultCache.
◆ Promote()
virtual void olp::cache::KeyValueCache::Promote |
( |
const std::string & |
key | ) |
|
|
inlinevirtual |
Promotes a key in the cache LRU when applicable.
- Parameters
-
key | The key to promote in the cache LRU. |
Reimplemented in olp::cache::DefaultCache.
◆ Protect()
virtual bool olp::cache::KeyValueCache::Protect |
( |
const KeyListType & |
keys | ) |
|
|
inlinevirtual |
Protects keys from eviction.
You can use keys or prefixes to protect single keys or entire catalogs, layers, or version.
- Parameters
-
keys | The list of keys or prefixes. |
- Returns
- True if the keys are added to the protected list; false otherwise.
Reimplemented in olp::cache::DefaultCache.
◆ Put() [1/2]
virtual bool olp::cache::KeyValueCache::Put |
( |
const std::string & |
key, |
|
|
const boost::any & |
value, |
|
|
const Encoder & |
encoder, |
|
|
time_t |
expiry = kDefaultExpiry |
|
) |
| |
|
pure virtual |
Stores the key-value pair in the cache.
- Parameters
-
key | The key for this value. |
value | The value of any type. |
encoder | Encodes the specified value into a string. |
expiry | The expiry time (in seconds) of the key-value pair. |
- Returns
- True if the operation is successful; false otherwise.
Implemented in olp::cache::DefaultCache.
◆ Put() [2/2]
Stores the raw binary data as a value in the cache.
- Parameters
-
key | The key for this value. |
value | The binary data that should be stored. |
expiry | The expiry time (in seconds) of the key-value pair. |
- Returns
- True if the operation is successful; false otherwise.
Implemented in olp::cache::DefaultCache.
◆ Release()
virtual bool olp::cache::KeyValueCache::Release |
( |
const KeyListType & |
keys | ) |
|
|
inlinevirtual |
Removes a list of keys from protection.
The provided keys can be full keys or prefixes only.
- Parameters
-
keys | The list of keys or prefixes. |
- Returns
- True if the keys are removed from the protected list; false otherwise.
Reimplemented in olp::cache::DefaultCache.
◆ Remove()
virtual bool olp::cache::KeyValueCache::Remove |
( |
const std::string & |
key | ) |
|
|
pure virtual |
Removes the key-value pair from the cache.
- Parameters
-
key | The key for the value. |
- Returns
- True if the operation is successful; false otherwise.
Implemented in olp::cache::DefaultCache.
◆ RemoveKeysWithPrefix()
virtual bool olp::cache::KeyValueCache::RemoveKeysWithPrefix |
( |
const std::string & |
prefix | ) |
|
|
pure virtual |
Removes the values with the keys that match the given prefix from the cache.
- Parameters
-
prefix | The prefix that matches the keys. |
- Returns
- True if the values are removed; false otherwise.
Implemented in olp::cache::DefaultCache.
◆ kDefaultExpiry
constexpr time_t olp::cache::KeyValueCache::kDefaultExpiry = std::numeric_limits<time_t>::max() |
|
staticconstexpr |
The expiry time of the key-value pair.
By default, the key-value pair has no expiry time.
The documentation for this class was generated from the following file: