BloombergLP::bdlcc::Cache

This class represents a simple in-process key-value store supporting a variety of eviction policies.

Synopsis

Declared in <bdlcc_cache.h>

template<
    class KEY,
    class VALUE,
    class HASH = bsl::hash<KEY>,
    class EQUAL = bsl::equal_to<KEY>>
class Cache;

Type Aliases

NameDescription
KVType Value type of a bulk insert entry.
PostEvictionCallback Type of function to call after an item has been evicted from the cache.
ValuePtrType Shared pointer type pointing to value type.

Member Functions

NameDescription
Cache [constructor]Constructors
clear Remove all items from this cache. Do not invoke the post-eviction callback.
equalFunction Return (a copy of) the key-equality functor used by this cache that returns true if two KEY objects have the same value, and false otherwise.
erase Remove the item having the specified key from this cache. Invoke the post-eviction callback for the removed item. Return 0 on success and 1 if key does not exist.
eraseBulk eraseBulk overloads
evictionPolicy Return the eviction policy used by this cache.
hashFunction Return (a copy of) the unary hash functor used by this cache to generate a hash value (of type std::size_t) for a KEY object.
highWatermark Return the high watermark of this cache, which is the size at which eviction of existing items begins.
insert insert overloads
insertBulk insertBulk overloads
lowWatermark Return the low watermark of this cache, which is the size at which eviction of existing items ends.
popFront Remove the item at the front of the eviction queue. Invoke the post-eviction callback for the removed item. Return 0 on success, and 1 if this cache is empty.
setPostEvictionCallback Set the post-eviction callback to the specified postEvictionCallback. The post-eviction callback is invoked for each item evicted or removed from this cache.
size Return the current size of this cache.
tryGetValue 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.
visit 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&)

Friends

NameDescription
BloombergLP::bdlcc::Cache_TestUtilThis class implements a test utility that gives the test driver access to the lock / unlock method of the RW mutex. Its purpose is to allow testing that the locking actually happens as planned.