[#BloombergLP-bdlcc-Cache]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlcc.adoc[bdlcc]::Cache
:relfileprefix: ../../
:mrdocs:

This class represents a simple in&hyphen;process key&hyphen;value store supporting a variety of eviction policies&period;

== Synopsis

Declared in `&lt;bdlcc&lowbar;cache&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class KEY,
    class VALUE,
    class HASH = xref:bsl/hash-06.adoc[bsl::hash&lt;KEY&gt;],
    class EQUAL = xref:bsl/equal_to-0d.adoc[bsl::equal&lowbar;to&lt;KEY&gt;]&gt;
class Cache;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlcc/Cache/KVType.adoc[`KVType`] 
| Value type of a bulk insert entry&period;
| xref:BloombergLP/bdlcc/Cache/PostEvictionCallback.adoc[`PostEvictionCallback`] 
| Type of function to call after an item has been evicted from the cache&period;
| xref:BloombergLP/bdlcc/Cache/ValuePtrType.adoc[`ValuePtrType`] 
| Shared pointer type pointing to value type&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlcc/Cache/2constructor-0a7.adoc[`Cache`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bdlcc/Cache/clear.adoc[`clear`] 
| Remove all items from this cache&period; Do _not_ invoke the post&hyphen;eviction callback&period;
| xref:BloombergLP/bdlcc/Cache/equalFunction.adoc[`equalFunction`] 
| Return (a copy of) the key&hyphen;equality functor used by this cache that returns `true` if two `KEY` objects have the same value, and `false` otherwise&period;
| xref:BloombergLP/bdlcc/Cache/erase.adoc[`erase`] 
| Remove the item having the specified `key` from this cache&period; Invoke the post&hyphen;eviction callback for the removed item&period; Return 0 on success and 1 if `key` does not exist&period;
| xref:BloombergLP/bdlcc/Cache/eraseBulk-0d.adoc[`eraseBulk`] 
| `eraseBulk` overloads
| xref:BloombergLP/bdlcc/Cache/evictionPolicy.adoc[`evictionPolicy`] 
| Return the eviction policy used by this cache&period;
| xref:BloombergLP/bdlcc/Cache/hashFunction.adoc[`hashFunction`] 
| Return (a copy of) the unary hash functor used by this cache to generate a hash value (of type `std&colon;&colon;size&lowbar;t`) for a `KEY` object&period;
| xref:BloombergLP/bdlcc/Cache/highWatermark.adoc[`highWatermark`] 
| Return the high watermark of this cache, which is the size at which eviction of existing items begins&period;
| xref:BloombergLP/bdlcc/Cache/insert-08.adoc[`insert`] 
| `insert` overloads
| xref:BloombergLP/bdlcc/Cache/insertBulk-0d.adoc[`insertBulk`] 
| `insertBulk` overloads
| xref:BloombergLP/bdlcc/Cache/lowWatermark.adoc[`lowWatermark`] 
| Return the low watermark of this cache, which is the size at which eviction of existing items ends&period;
| xref:BloombergLP/bdlcc/Cache/popFront.adoc[`popFront`] 
| Remove the item at the front of the eviction queue&period; Invoke the post&hyphen;eviction callback for the removed item&period; Return 0 on success, and 1 if this cache is empty&period;
| xref:BloombergLP/bdlcc/Cache/setPostEvictionCallback.adoc[`setPostEvictionCallback`] 
| Set the post&hyphen;eviction callback to the specified `postEvictionCallback`&period; The post&hyphen;eviction callback is invoked for each item evicted or removed from this cache&period;
| xref:BloombergLP/bdlcc/Cache/size.adoc[`size`] 
| Return the current size of this cache&period;
| xref:BloombergLP/bdlcc/Cache/tryGetValue.adoc[`tryGetValue`] 
| Load, into the specified `value`, the value associated with the specified `key` in this cache&period; 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&period; Return 0 on success, and 1 if `key` does not exist in this cache&period; Note that a write lock is acquired only if this queue is modified&period;
| xref:BloombergLP/bdlcc/Cache/visit.adoc[`visit`] 
| Call the specified `visitor` for every item stored in this cache in the order of the eviction queue until `visitor` returns `false`&period; The `VISITOR` type must be a callable object that can be invoked in the same way as the function `bool (const KEY&amp;, const VALUE&amp;)`
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bdlcc/Cache_TestUtil.adoc[BloombergLP::bdlcc::Cache&lowbar;TestUtil]`
| This class implements a test utility that gives the test driver access to the lock &sol; unlock method of the RW mutex&period; Its purpose is to allow testing that the locking actually happens as planned&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
