Skip to content

caches::LRUCachePolicy

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

#include <lru_cache_policy.hpp>

Inherits from caches::ICachePolicy< Key >

Public Types

Name
using typename std::list< Key >::iterator lru_iterator

Public Functions

Name
LRUCachePolicy() =default
~LRUCachePolicy() =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::LRUCachePolicy;

LRU (Least Recently Used) cache policy.

Template Parameters:

  • Key Type of a key a policy works with

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

Public Types Documentation

using lru_iterator

using caches::LRUCachePolicy< Key >::lru_iterator =  typename std::list<Key>::iterator;

Public Functions Documentation

function LRUCachePolicy

LRUCachePolicy() =default

function ~LRUCachePolicy

~LRUCachePolicy() =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