caches::LFUCachePolicy
LFU (Least frequently used) cache policy. More...
#include <lfu_cache_policy.hpp>
Inherits from caches::ICachePolicy< Key >
Public Types
Name | |
---|---|
using typename std::multimap< std::size_t, Key >::iterator | lfu_iterator |
Public Functions
Name | |
---|---|
LFUCachePolicy() =default | |
~LFUCachePolicy() override =default | |
virtual void | Insert(const Key & key) override Handle element insertion in a cache. |
virtual void | Touch(const Key & key) override Handle request to the key-element in a cache. |
virtual void | Erase(const Key & key) override Handle element deletion from a cache. |
virtual const Key & | ReplCandidate() const override Return a key of a replacement candidate. |
Additional inherited members
Public Functions inherited from caches::ICachePolicy< Key >
Name | |
---|---|
virtual | ~ICachePolicy() =default |
Detailed Description
template <typename Key >
class caches::LFUCachePolicy;
LFU (Least frequently used) cache policy.
Template Parameters:
- Key Type of a key a policy works with
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.
Public Types Documentation
using lfu_iterator
using caches::LFUCachePolicy< Key >::lfu_iterator = typename std::multimap<std::size_t, Key>::iterator;
Public Functions Documentation
function LFUCachePolicy
LFUCachePolicy() =default
function ~LFUCachePolicy
~LFUCachePolicy() override =default
function Insert
inline virtual void Insert(
const Key & key
) override
Handle element insertion in a cache.
Parameters:
- key Key that should be used by the policy
Reimplements: caches::ICachePolicy::Insert
function Touch
inline virtual void Touch(
const Key & key
) override
Handle request to the key-element in a cache.
Parameters:
- key
Reimplements: caches::ICachePolicy::Touch
function Erase
inline virtual void Erase(
const Key & key
) override
Handle element deletion from a cache.
Parameters:
- key Key that should be used by the policy
Reimplements: caches::ICachePolicy::Erase
function ReplCandidate
inline virtual const Key & ReplCandidate() const override
Return a key of a replacement candidate.
Return: Replacement candidate according to selected policy
Reimplements: caches::ICachePolicy::ReplCandidate