1 Star 0 Fork 0

khiphop / cGroupCache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cache.hpp 631 Bytes
一键复制 编辑 原始数据 按行查看 历史
khiphop 提交于 2022-01-12 16:48 . Initial commit
/**
* System design: LRU cache (least recently used).
*/
#include<iostream>
#include<map>
#include <mutex>
#include <thread>
#include "lru.hpp"
using namespace std;
class MainCache {
private:
mutex mu;
LruCache *lruCache;
public:
MainCache(int capacity, int ttl) {
lruCache = new LruCache(capacity, ttl);
}
bool set(string key, string val) {
mu.lock();
lruCache->set(key, val.c_str());
mu.unlock();
return true;
}
string get(string key) {
mu.lock();
string val = lruCache->get(key);
mu.unlock();
return val;
}
};
C++
1
https://gitee.com/khiphop/cGroupCache.git
git@gitee.com:khiphop/cGroupCache.git
khiphop
cGroupCache
cGroupCache
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891