Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s12mmm3/cachehandler
基于std::tuple实现的函数缓存管理 (Function cache management based on std::tuple)
https://github.com/s12mmm3/cachehandler
cpp stl
Last synced: 6 days ago
JSON representation
基于std::tuple实现的函数缓存管理 (Function cache management based on std::tuple)
- Host: GitHub
- URL: https://github.com/s12mmm3/cachehandler
- Owner: s12mmm3
- License: mit
- Created: 2024-02-17T05:08:40.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-02-21T13:00:56.000Z (11 months ago)
- Last Synced: 2024-11-11T17:15:48.617Z (2 months ago)
- Topics: cpp, stl
- Language: C++
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CacheHandler
CacheHandler是一个C++模板类,用于实现缓存管理的功能。它可以根据给定的函数,参数,超时时间和最大容量,自动缓存函数的返回值,并在需要时更新缓存。
## 使用方法
- 需要包含CacheHandler.h头文件```cpp
#include "CacheHandler.h"// Define a function that takes two integers and returns their sum
double add(int a, int b) {
return a + b;
}int main() {
// Create a CacheHandler object with add function, 10 seconds timeout and 5 items max size
CacheHandler cache(add, 10000, 5);// You can use lambda too
CacheHandler cache1([](int a, int b) -> double {
return a + b;
}, 10000, 5);// Get the value of add(1, 2) and cache it
int result = cache.value(1, 2);
std::cout << result << std::endl;result = cache.value(1, 2);
std::cout << result << std::endl;return 0;
}
```