cjcchen commented on code in PR #170:
URL:
https://github.com/apache/incubator-resilientdb/pull/170#discussion_r1954307163
##########
common/lru/lru_cache.h:
##########
@@ -0,0 +1,46 @@
+#include <deque>
+#include <unordered_map>
+
+using namespace std;
+
+namespace resdb {
+
+template <typename KeyType, typename ValueType>
+class LRUCache {
+ public:
+ // Constructor to initialize the cache with a given capacity
+ LRUCache(int capacity);
+
+ // Destructor
+ ~LRUCache();
+
+ // Get the value of the key if present in the cache
+ ValueType Get(KeyType key);
+
+ // Insert or update the key-value pair
+ void Put(KeyType key, ValueType value);
+
+ // Method to change the cache capacity
+ void SetCapacity(int new_capacity);
+
+ // Method to flush the cache (clear all entries)
+ void Flush();
+
+ // Method to get the cache hit count
+ int GetCacheHits() const;
+
+ // Method to get the cache miss count
+ int GetCacheMisses() const;
+
+ // Method to get the cache Hit Ratio
+ double GetCacheHitRatio() const;
+
+ private:
+ int m_; // Cache capacity
+ int cache_hits_; // Cache hits count
+ int cache_misses_; // Cache misses count
+
+ deque<KeyType> dq_; // To maintain most and least recently used items
Review Comment:
why not use link-list?
https://en.cppreference.com/w/cpp/container/list
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]