Electroneum
fifo_cache_policy.hpp
Go to the documentation of this file.
1 #ifndef FIFO_CACHE_POLICY_HPP
2 #define FIFO_CACHE_POLICY_HPP
3 
4 #include <list>
5 #include "cache_policy.hpp"
6 
7 namespace caches
8 {
9 
10 template <typename Key>
11 class FIFOCachePolicy : public ICachePolicy<Key>
12 {
13  public:
14 
15  FIFOCachePolicy() = default;
16  ~FIFOCachePolicy() = default;
17 
18  void Insert(const Key& key) override
19  {
20  fifo_queue.emplace_front(key);
21  }
22 
23  // handle request to the key-element in a cache
24  void Touch(const Key& key) override
25  {
26  // nothing to do here in the FIFO strategy
27  }
28 
29  // handle element deletion from a cache
30  void Erase(const Key& key) override
31  {
32  fifo_queue.pop_back();
33  }
34 
35  // return a key of a replacement candidate
36  const Key& ReplCandidate() const override
37  {
38  return fifo_queue.back();
39  }
40 
41  // return a key of a displacement candidate
42  void Clear() override
43  {
44  fifo_queue.clear();
45  }
46 
47 private:
48 
49  std::list<Key> fifo_queue;
50 };
51 } // namespace caches
52 
53 #endif // FIFO_CACHE_POLICY_HPP
const Key & ReplCandidate() const override
Definition: fifo_cache_policy.hpp:36
void Touch(const Key &key) override
Definition: fifo_cache_policy.hpp:24
std::list< Key > fifo_queue
Definition: fifo_cache_policy.hpp:49
void Insert(const Key &key) override
Definition: fifo_cache_policy.hpp:18
void Erase(const Key &key) override
Definition: fifo_cache_policy.hpp:30
Definition: fifo_cache_policy.hpp:11
void Clear() override
Definition: fifo_cache_policy.hpp:42
Definition: cache_policy.hpp:11
Definition: cache.hpp:11