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
|
| | 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 |
| |
| 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 |
| |
| HASH | hashFunction () const |
| |
| bsl::size_t | highWatermark () const |
| |
| bsl::size_t | lowWatermark () const |
| |
| bsl::size_t | size () const |
| |
| template<class VISITOR > |
| void | visit (VISITOR &visitor) const |
| |
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.
- Precondition
- 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 >
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
- 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&)