|
| Cache (bslma::Allocator *basicAllocator=0) |
|
| Cache (CacheEvictionPolicy::Enum evictionPolicy, bsl::size_t lowWatermark, bsl::size_t highWatermark, bslma::Allocator *basicAllocator=0) |
|
| Cache (CacheEvictionPolicy::Enum evictionPolicy, bsl::size_t lowWatermark, bsl::size_t highWatermark, const HASH &hashFunction, const EQUAL &equalFunction, bslma::Allocator *basicAllocator=0) |
|
| ~Cache ()=default |
| Destroy this object.
|
|
void | clear () |
|
int | erase (const KEY &key) |
|
template<class INPUT_ITERATOR > |
int | eraseBulk (INPUT_ITERATOR begin, INPUT_ITERATOR end) |
|
int | eraseBulk (const bsl::vector< KEY > &keys) |
|
void | insert (const KEY &key, const VALUE &value) |
|
void | insert (const KEY &key, bslmf::MovableRef< VALUE > value) |
|
void | insert (bslmf::MovableRef< KEY > key, const VALUE &value) |
|
void | insert (bslmf::MovableRef< KEY > key, bslmf::MovableRef< VALUE > value) |
|
void | insert (const KEY &key, const ValuePtrType &valuePtr) |
|
void | insert (bslmf::MovableRef< KEY > key, const ValuePtrType &valuePtr) |
|
template<class INPUT_ITERATOR > |
int | insertBulk (INPUT_ITERATOR begin, INPUT_ITERATOR end) |
|
int | insertBulk (const bsl::vector< KVType > &data) |
|
int | insertBulk (bslmf::MovableRef< bsl::vector< KVType > > data) |
|
int | popFront () |
|
void | setPostEvictionCallback (const PostEvictionCallback &postEvictionCallback) |
|
int | tryGetValue (bsl::shared_ptr< VALUE > *value, const KEY &key, bool modifyEvictionQueue=true) |
|
EQUAL | equalFunction () const |
|
CacheEvictionPolicy::Enum | evictionPolicy () const |
| Return the eviction policy used by this cache.
|
|
HASH | hashFunction () const |
|
bsl::size_t | highWatermark () const |
|
bsl::size_t | lowWatermark () const |
|
bsl::size_t | size () const |
| Return the current size of this cache.
|
|
template<class VISITOR > |
void | visit (VISITOR &visitor) const |
|
template<class KEY, class VALUE, class HASH = bsl::hash<KEY>, class EQUAL = bsl::equal_to<KEY>>
class bdlcc::Cache< KEY, VALUE, HASH, EQUAL >
This class represents a simple in-process key-value store supporting a variety of eviction policies.
See bdlcc_cache
template<class KEY , class VALUE , class HASH , class EQUAL >
Create an empty cache using the specified evictionPolicy
and the specified lowWatermark
and highWatermark
. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The behavior is undefined unless lowWatermark <= highWatermark
, 1 <= lowWatermark
, and 1 <= highWatermark
.
template<class KEY , class VALUE , class HASH , class EQUAL >
Create an empty cache using the specified evictionPolicy
, lowWatermark
, and highWatermark
. The specified hashFunction
is used to generate the hash values for a given key, and the specified equalFunction
is used to determine whether two keys have the same value. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The behavior is undefined unless lowWatermark <= highWatermark
, 1 <= lowWatermark
, and 1 <= highWatermark
.
template<class KEY , class VALUE , class HASH , class EQUAL >
template<class INPUT_ITERATOR >
int bdlcc::Cache< KEY, VALUE, HASH, EQUAL >::eraseBulk |
( |
INPUT_ITERATOR |
begin, |
|
|
INPUT_ITERATOR |
end |
|
) |
| |
Remove the items having the keys in the specified range [ begin, end )
, from this cache. Invoke the post-eviction callback for each removed item. Return the number of items successfully removed.
template<class KEY , class VALUE , class HASH , class EQUAL >
Move the specified key
and its associated value
into this cache. If key
already exists, then its value will be replaced with value
. Note that all the methods that take moved objects provide the basic
but not the strong
exception guarantee – throws may occur after the objects are moved out of; the cache will not be modified, but key
or value
may be changed. Also note that key
must be copyable, even if it is moved.
template<class KEY , class VALUE , class HASH , class EQUAL >
Insert the specified key
and its associated valuePtr
into this cache. If key
already exists, then its value will be replaced with value
. Note that the method with key
moved provides the basic
but not the strong
exception guarantee – if a throw occurs, the cache will not be modified, but key
may be changed. Also note that key
must be copyable, even if it is moved.
template<class KEY , class VALUE , class HASH , class EQUAL >
Insert the specified data
(composed of Key-Value pairs) into this cache. If a key already exists, then its value will be replaced with the value. Return the number of items successfully inserted. If an exception occurs during this action, we provide only the basic guarantee - both this cache and data
will be in some valid but unspecified state.
template<class KEY , class VALUE , class HASH , class EQUAL >
template<class INPUT_ITERATOR >
int bdlcc::Cache< KEY, VALUE, HASH, EQUAL >::insertBulk |
( |
INPUT_ITERATOR |
begin, |
|
|
INPUT_ITERATOR |
end |
|
) |
| |
Insert the specified range of Key-Value pairs specified by [ begin, end )
into this cache. If a key already exists, then its value will be replaced with the value. Return the number of items successfully inserted.
template<class KEY , class VALUE , class HASH , class EQUAL >
int bdlcc::Cache< KEY, VALUE, HASH, EQUAL >::tryGetValue |
( |
bsl::shared_ptr< VALUE > * |
value, |
|
|
const KEY & |
key, |
|
|
bool |
modifyEvictionQueue = true |
|
) |
| |
Load, into the specified value
, the value associated with the specified key
in this cache. If the optionally specified modifyEvictionQueue
is true
and the eviction policy is LRU, then move the cached item to the back of the eviction queue. Return 0 on success, and 1 if key
does not exist in this cache. Note that a write lock is acquired only if this queue is modified.
template<class KEY , class VALUE , class HASH , class EQUAL >
template<class VISITOR >
void bdlcc::Cache< KEY, VALUE, HASH, EQUAL >::visit |
( |
VISITOR & |
visitor | ) |
const |
Call the specified visitor
for every item stored in this cache in the order of the eviction queue until visitor
returns false
. The VISITOR
type must be a callable object that can be invoked in the same way as the function bool (const KEY&, const VALUE&)