5#ifndef FIFO_CACHE_POLICY_HPP
6#define FIFO_CACHE_POLICY_HPP
10#include <unordered_map>
34template <
typename Key>
38 using fifo_iterator =
typename std::list<Key>::const_iterator;
45 fifo_queue.emplace_front(key);
46 key_lookup[key] = fifo_queue.begin();
49 void Touch(
const Key &key)
noexcept override
55 void Erase(
const Key &key)
noexcept override
57 auto element = key_lookup[key];
58 fifo_queue.erase(element);
59 key_lookup.erase(key);
65 return fifo_queue.back();
69 std::list<Key> fifo_queue;
70 std::unordered_map<Key, fifo_iterator> key_lookup;
Cache policy interface declaration.
FIFO (First in, first out) cache policy.
Definition: fifo_cache_policy.hpp:36
void Insert(const Key &key) override
Handle element insertion in a cache.
Definition: fifo_cache_policy.hpp:43
void Touch(const Key &key) noexcept override
Handle request to the key-element in a cache.
Definition: fifo_cache_policy.hpp:49
void Erase(const Key &key) noexcept override
Handle element deletion from a cache.
Definition: fifo_cache_policy.hpp:55
const Key & ReplCandidate() const noexcept override
Return a key of a replacement candidate.
Definition: fifo_cache_policy.hpp:63
Cache policy abstract base class.
Definition: cache_policy.hpp:19