百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

caches

> 编程语言
开源

带有 LRU/LFU/FIFO 策略的 C++ 缓存实现

382 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

带有 LRU/LFU/FIFO 策略的 C++ 缓存实现

C++ Cache implementation

This project implements a simple thread-safe cache with several page replacement policies:

  • Least Recently Used
  • First-In/First-Out
  • Least Frequently Used

More about cache algorithms and policy you could read on Wikipedia

Usage

Using this library is simple. It is necessary to include header with the cache implementation (caches/cache.hpp file) and appropriate header with the cache policy if it is needed. If not then the non-special algorithm will be used (it removes the last element which key is the last in the internal container).

Currently, there is only three of them:

  • fifo_cache_policy.hpp
  • lfu_cache_policy.hpp
  • lru_cache_policy.hpp

Example for the LRU policy:

cpp
#include 
#include "caches/cache.hpp"
#include "caches/lru_cache_policy.hpp"

// alias for an easy class typing
template 
using lru_cache_t = typename caches::fixed_sized_cache;

void foo() {
  constexpr std::size_t CACHE_SIZE = 256;
  lru_cache_t cache(CACHE_SIZE);

  cache.Put("Hello", 1);
  cache.Put("world", 2);
  
  const auto hello_value = cache.Get("Hello");
  const auto world_value = cache.Get("world");

  std::cout 
using lru_cache_t = typename caches::fixed_sized_cache>;
// ...
lru_cache_t cache{16};
cache.Put("Hello", 1);
std::cout << *cache.Get("Hello") << '\n';

See test implementation which uses parallel-hashmap.

Requirements

The only requirement is a compatible C++11 compiler.

This project was tested in the environments listed below:

  • MinGW64 (MSYS2 project)
    • Clang 13.0+
    • GCC 7+
  • MSVC (VS 2015)

If you have any issues with the library building, please let me know.

Contributing

Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++c-plus-pluscachecppcpp11

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言