#pragma once #include #include #include #include "rediska/cache/lru/LRUConfig.hpp" #include "rediska/cache/lru/LRUItemMetadata.hpp" #include "rediska/cache/types.hpp" #include "rediska/common/MessageArguments.hpp" #include "rediska/common/types.hpp" #include "rediska/cache/CachePolicy.hpp" namespace cache { class LRU : public CachePolicy { public: using ItemMetadata = LRUItemMetadata; using ItemHandle = struct { CacheValue value; ItemMetadata metadata; }; using CacheNode = struct { CacheKey key; ItemHandle location; }; LRU(LRUConfig config, CacheOpCallback callback); ~LRU() = default; void get(CacheKey&& key) override; void set(CacheKey&& key, CacheValue&& value, TTL ttl) override; void applyTo(CacheKey&& key, OperationId op, MessageArguments&& args) override; private: std::list lru_list_; std::unordered_map::iterator> keyToItem_; std::shared_mutex mutex_; LRUConfig config_; CacheOpCallback callback_; void evict() override; void evict(const std::unordered_map::iterator>::iterator node); inline bool isFull() const override; void resetTTLIfEnabled(CacheNode& key); }; }