|
Squid Web Cache master
|
#include <ClpMap.h>
Classes | |
| class | Entry |
| the keeper of cache entry Key, Value, and caching-related entry metadata More... | |
Public Types | |
| using | key_type = Key |
| using | mapped_type = Value |
| using | Ttl = int |
| maximum desired entry caching duration (a.k.a. TTL), in seconds | |
| using | Entries = std::list< Entry, PoolingAllocator< Entry > > |
| Entries in LRU order. | |
| using | EntriesIterator = typename Entries::iterator |
| using | ConstEntriesIterator = typename Entries::const_iterator |
Public Member Functions | |
| ClpMap (const uint64_t capacity) | |
| ClpMap (uint64_t capacity, Ttl defaultTtl) | |
| ~ClpMap ()=default | |
| ClpMap (const ClpMap &)=delete | |
| ClpMap & | operator= (const ClpMap &)=delete |
| const Value * | get (const Key &) |
| bool | add (const Key &, const Value &, Ttl) |
| bool | add (const Key &key, const Value &v) |
| Copy the given value into the map (with the given key and default TTL) | |
| void | del (const Key &) |
| Remove the corresponding entry (if any) | |
| void | setMemLimit (uint64_t newLimit) |
| Reset the memory capacity for this map, purging if needed. | |
| uint64_t | memLimit () const |
| The memory capacity for the map. | |
| uint64_t | freeMem () const |
| The free space of the map. | |
| uint64_t | memoryUsed () const |
| The current (approximate) memory usage of the map. | |
| size_t | entries () const |
| The number of currently stored entries, including expired ones. | |
| ConstEntriesIterator | cbegin () const |
| ConstEntriesIterator | cend () const |
| ConstEntriesIterator | begin () const |
range-based for loop support; | |
| ConstEntriesIterator | end () const |
Private Types | |
| using | IndexItem = std::pair< const Key, EntriesIterator > |
| using | Index = std::unordered_map< Key, EntriesIterator, std::hash< Key >, std::equal_to< Key >, PoolingAllocator< IndexItem > > |
| key:entry_position mapping for fast entry lookups by key | |
| using | IndexIterator = typename Index::iterator |
Private Member Functions | |
| void | trim (uint64_t wantSpace) |
| purges entries to make free memory large enough to fit wantSpace bytes | |
| void | erase (const IndexIterator &) |
| removes the cached entry (identified by its index) from the map | |
| IndexIterator | find (const Key &) |
Static Private Member Functions | |
| static std::optional< uint64_t > | MemoryCountedFor (const Key &, const Value &) |
Private Attributes | |
| Entries | entries_ |
| cached entries, including expired ones, in LRU order | |
| Index | index_ |
| entries_ positions indexed by the entry key | |
| Ttl | defaultTtl_ = std::numeric_limits<Ttl>::max() |
| entry TTL to use if none provided to add() | |
| uint64_t | memLimit_ = 0 |
| the maximum memory we are allowed to use for all cached entries | |
| uint64_t | memUsed_ = 0 |
| the total amount of memory we currently use for all cached entries | |
An in-memory associative container enforcing three primary caching policies:
Value must meet STL requirements of Erasable and EmplaceConstructible. Key must come with std::hash<Key> and std::equal_to<Key> instantiations. Key::length() must return the number of memory bytes in use by the key. MemoryUsedBy() must return the number of memory bytes in use by the value.
| using ClpMap< Key, Value, MemoryUsedBy >::ConstEntriesIterator = typename Entries::const_iterator |
| using ClpMap< Key, Value, MemoryUsedBy >::Entries = std::list<Entry, PoolingAllocator<Entry> > |
| using ClpMap< Key, Value, MemoryUsedBy >::EntriesIterator = typename Entries::iterator |
|
private |
|
private |
|
private |
| using ClpMap< Key, Value, MemoryUsedBy >::key_type = Key |
| using ClpMap< Key, Value, MemoryUsedBy >::mapped_type = Value |
|
inlineexplicit |
Definition at line 70 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::setMemLimit().
| ClpMap< Key, Value, MemoryUsedBy >::ClpMap | ( | uint64_t | capacity, |
| Ttl | defaultTtl | ||
| ) |
Definition at line 149 of file ClpMap.h.
References assert, and ClpMap< Key, Value, MemoryUsedBy >::setMemLimit().
|
default |
|
delete |
| bool ClpMap< Key, Value, MemoryUsedBy >::add | ( | const Key & | key, |
| const Value & | v, | ||
| Ttl | ttl | ||
| ) |
Copy the given value into the map (with the given key and TTL)
| true | the value was successfully copied into the map |
| false | caching was rejected (the map remains unchanged) |
Definition at line 220 of file ClpMap.h.
References addedEntry(), and assert.
Referenced by TestClpMap::addOneEntry(), TestClpMap::addOneEntry(), TestClpMap::addSequenceOfEntriesToMap(), TestClpMap::testEntryCounter(), TestClpMap::testNegativeTtl(), and TestClpMap::testPutGetDelete().
|
inline |
Definition at line 91 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::add(), and ClpMap< Key, Value, MemoryUsedBy >::defaultTtl_.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::add().
|
inline |
Definition at line 117 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::cbegin().
|
inline |
Read-only traversal of all cached entries in LRU order, least recently used entry first. Stored expired entries (if any) are included. Any map modification may invalidate these iterators and their derivatives.
Definition at line 114 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::entries_.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::begin(), and TestClpMap::testClassicLoopTraversal().
|
inline |
Definition at line 115 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::entries_.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::end(), and TestClpMap::testClassicLoopTraversal().
| void ClpMap< Key, Value, MemoryUsedBy >::del | ( | const Key & | key | ) |
Definition at line 268 of file ClpMap.h.
Referenced by TestClpMap::testMisses(), and TestClpMap::testPutGetDelete().
|
inline |
Definition at line 118 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::cend().
|
inline |
Definition at line 109 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::entries_.
Referenced by TestClpMap::testConstructor(), TestClpMap::testEntryCounter(), TestClpMap::testMemoryLimit(), and TestClpMap::testMisses().
|
private |
|
private |
|
inline |
Definition at line 103 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::memLimit(), and ClpMap< Key, Value, MemoryUsedBy >::memoryUsed().
Referenced by TestClpMap::testConstructor().
| const Value * ClpMap< Key, Value, MemoryUsedBy >::get | ( | const Key & | key | ) |
Definition at line 188 of file ClpMap.h.
Referenced by TestClpMap::addOneEntry(), TestClpMap::addOneEntry(), TestClpMap::testMisses(), TestClpMap::testNegativeTtl(), TestClpMap::testPurgeIsLru(), TestClpMap::testPutGetDelete(), TestClpMap::testReplaceEntryWithShorterTtl(), TestClpMap::testTtlExpiration(), and TestClpMap::testZeroTtl().
|
inline |
Definition at line 100 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::memLimit_.
Referenced by TestClpMap::fillMapWithEntries(), ClpMap< Key, Value, MemoryUsedBy >::freeMem(), and TestClpMap::testConstructor().
|
staticprivate |
|
inline |
Definition at line 106 of file ClpMap.h.
References ClpMap< Key, Value, MemoryUsedBy >::memUsed_.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::freeMem(), TestClpMap::testConstructor(), and TestClpMap::testMemoryLimit().
|
delete |
| void ClpMap< Key, Value, MemoryUsedBy >::setMemLimit | ( | uint64_t | newLimit | ) |
Definition at line 158 of file ClpMap.h.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::ClpMap(), ClpMap< Key, Value, MemoryUsedBy >::ClpMap(), and TestClpMap::testMemoryLimit().
|
private |
|
private |
Definition at line 139 of file ClpMap.h.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::add().
|
private |
Definition at line 133 of file ClpMap.h.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::cbegin(), ClpMap< Key, Value, MemoryUsedBy >::cend(), and ClpMap< Key, Value, MemoryUsedBy >::entries().
|
private |
Definition at line 142 of file ClpMap.h.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::memLimit().
|
private |
Definition at line 145 of file ClpMap.h.
Referenced by ClpMap< Key, Value, MemoryUsedBy >::memoryUsed().