mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
53 lines
946 B
C++
53 lines
946 B
C++
#ifndef FIFO_CACHE_POLICY_HPP
|
|
#define FIFO_CACHE_POLICY_HPP
|
|
|
|
#include <list>
|
|
#include "cache_policy.hpp"
|
|
|
|
namespace caches
|
|
{
|
|
|
|
template <typename Key>
|
|
class FIFOCachePolicy : public ICachePolicy<Key>
|
|
{
|
|
public:
|
|
|
|
FIFOCachePolicy() = default;
|
|
~FIFOCachePolicy() = default;
|
|
|
|
void Insert(const Key& key) override
|
|
{
|
|
fifo_queue.emplace_front(key);
|
|
}
|
|
|
|
// handle request to the key-element in a cache
|
|
void Touch(const Key& key) override
|
|
{
|
|
// nothing to do here in the FIFO strategy
|
|
}
|
|
|
|
// handle element deletion from a cache
|
|
void Erase(const Key& key) override
|
|
{
|
|
fifo_queue.pop_back();
|
|
}
|
|
|
|
// return a key of a replacement candidate
|
|
const Key& ReplCandidate() const override
|
|
{
|
|
return fifo_queue.back();
|
|
}
|
|
|
|
// return a key of a displacement candidate
|
|
void Clear() override
|
|
{
|
|
fifo_queue.clear();
|
|
}
|
|
|
|
private:
|
|
|
|
std::list<Key> fifo_queue;
|
|
};
|
|
} // namespace caches
|
|
|
|
#endif // FIFO_CACHE_POLICY_HPP
|