Caches 0.1.0
LRU/LFU/FIFO Caches library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
caches::LRUCachePolicy< Key > Class Template Reference

LRU (Least Recently Used) cache policy. More...

#include <lru_cache_policy.hpp>

Inheritance diagram for caches::LRUCachePolicy< Key >:
Inheritance graph
[legend]
Collaboration diagram for caches::LRUCachePolicy< Key >:
Collaboration graph
[legend]

Public Types

using lru_iterator = typename std::list< 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 &) 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.
 

Detailed Description

template<typename Key>
class caches::LRUCachePolicy< Key >

LRU (Least Recently Used) cache policy.

LRU policy in the case of replacement removes the least recently used element. That is, in the case of replacement necessity, that cache policy returns a key that has not been touched recently. For example, cache maximum size is 3 and 3 elements have been added - A, B, C. Then the following actions were made:

Cache placement order: A, B, C
Cache elements: A, B, C
# Cache access:
- A touched, B touched
# LRU element in the cache: C
# Cache access:
- B touched, C touched
# LRU element in the cache: A
# Put new element: D
# LRU replacement candidate: A
Cache elements: B, C, D
Template Parameters
KeyType of a key a policy works with

Member Function Documentation

◆ Erase()

template<typename Key >
void caches::LRUCachePolicy< Key >::Erase ( const Key &  key)
inlineoverridevirtualnoexcept

Handle element deletion from a cache.

Parameters
[in]keyKey that should be used by the policy

Implements caches::ICachePolicy< Key >.

◆ Insert()

template<typename Key >
void caches::LRUCachePolicy< Key >::Insert ( const Key &  key)
inlineoverridevirtual

Handle element insertion in a cache.

Parameters
[in]keyKey that should be used by the policy

Implements caches::ICachePolicy< Key >.

◆ ReplCandidate()

template<typename Key >
const Key & caches::LRUCachePolicy< Key >::ReplCandidate ( ) const
inlineoverridevirtualnoexcept

Return a key of a replacement candidate.

Returns
Replacement candidate according to selected policy

Implements caches::ICachePolicy< Key >.

◆ Touch()

template<typename Key >
void caches::LRUCachePolicy< Key >::Touch ( const Key &  key)
inlineoverridevirtual

Handle request to the key-element in a cache.

Parameters
key

Implements caches::ICachePolicy< Key >.


The documentation for this class was generated from the following file: