Caches 0.1.0
LRU/LFU/FIFO Caches library
|
LFU (Least frequently used) cache policy. More...
#include <lfu_cache_policy.hpp>
Public Types | |
using | lfu_iterator = typename std::multimap< std::size_t, Key >::iterator |
Public Member Functions | |
void | Insert (const Key &key) override |
Handle element insertion in a cache. | |
void | Touch (const Key &key) override |
Handle request to the key-element in a cache. | |
void | Erase (const Key &key) noexcept override |
Handle element deletion from a cache. | |
const Key & | ReplCandidate () const noexcept override |
Return a key of a replacement candidate. | |
virtual void | Insert (const Key &key)=0 |
Handle element insertion in a cache. | |
virtual void | Touch (const Key &key)=0 |
Handle request to the key-element in a cache. | |
virtual void | Erase (const Key &key)=0 |
Handle element deletion from a cache. | |
virtual const Key & | ReplCandidate () const =0 |
Return a key of a replacement candidate. | |
LFU (Least frequently used) cache policy.
LFU policy in the case of replacement removes the least frequently used element.
Each access to an element in the cache increments internal counter (frequency) that represents how many times that particular key has been accessed by someone. When a replacement has to occur the LFU policy just takes a look onto keys' frequencies and remove the least used one. E.g. cache of two elements where A
has been accessed 10 times and B
– only 2. When you want to add a key C
the LFU policy returns B
as a replacement candidate.
Key | Type of a key a policy works with |
|
inlineoverridevirtualnoexcept |
Handle element deletion from a cache.
[in] | key | Key that should be used by the policy |
Implements caches::ICachePolicy< Key >.
|
inlineoverridevirtual |
Handle element insertion in a cache.
[in] | key | Key that should be used by the policy |
Implements caches::ICachePolicy< Key >.
|
inlineoverridevirtualnoexcept |
Return a key of a replacement candidate.
Implements caches::ICachePolicy< Key >.
|
inlineoverridevirtual |
Handle request to the key-element in a cache.
key |
Implements caches::ICachePolicy< Key >.