{"id":17672109,"url":"https://github.com/hengxin666/hxcache","last_synced_at":"2026-01-29T10:04:32.449Z","repository":{"id":259032747,"uuid":"875181142","full_name":"HengXin666/HXCache","owner":"HengXin666","description":"提供最低C++11即可使用的线程安全的LRU、LFU，只需要单头文件; 只依赖于STL, 支持原地构造和透明查找. | Providing thread-safe LRU, LFU with the lowest C++11 usage, only requires a single header file; depends only on STL, supports in-place construction and transparent lookup.","archived":false,"fork":false,"pushed_at":"2024-10-21T14:16:24.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T00:24:19.324Z","etag":null,"topics":["cache","cpp11","lfu-cache","lru-cache"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HengXin666.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-19T10:00:53.000Z","updated_at":"2025-03-05T13:39:33.000Z","dependencies_parsed_at":"2024-10-22T16:44:13.124Z","dependency_job_id":null,"html_url":"https://github.com/HengXin666/HXCache","commit_stats":null,"previous_names":["hengxin666/hxcache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HengXin666%2FHXCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HengXin666%2FHXCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HengXin666%2FHXCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HengXin666%2FHXCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HengXin666","download_url":"https://codeload.github.com/HengXin666/HXCache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249140807,"owners_count":21219361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cpp11","lfu-cache","lru-cache"],"created_at":"2024-10-24T04:06:58.760Z","updated_at":"2026-01-29T10:04:32.411Z","avatar_url":"https://github.com/HengXin666.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\" style=\"color:yellow\"\u003eHXCache\u003c/h1\u003e\n\n实现了线程安全的LRU、LFU，只需要单头文件; 只依赖于STL, 支持原地构造和透明查找.\n\n本项目是从 [HXNet](https://github.com/HengXin666/HXNet) 中分出来的(*并且特化支持C++20以下的内容*), 专门用于提供LRU、LFU等Cache.\n\n## 构建要求\n\n- 最低 C++11 (因为STL没有读写锁, 所以使用`std::mutex`)\n\n- C++14 此时支持`透明查找`(`contains`) (因为STL没有纯的读写锁, 所以使用`std::shared_timed_mutex`, 不过我相信在不使用定时的情况下, 性能损耗为 0)\n\n- C++17 (性能完全体, 使用`std::shared_mutex`)\n\n## 示例\n\n- [LRUCache/LFUCache的示例](examples/CacheTest.cpp)\n\n下面是一个简单的示例, LFU和LRU的的API是一样的.\n\n```C++\n#include \u003cHXCache/LFUCache.hpp\u003e\n\nint main() {\n    HX::ThreadSafeLFUCache\u003cint, std::string\u003e cache(2); // capacity = 2\n\n    cache.insert(123, \"This 123~\");\n    cache.emplace(456, \"This 456~\"); // 原地构造\n\n    const std::string\u0026 str = cache.get(123);\n\n    std::cout \u003c\u003c str \u003c\u003c '\\n'; // This 123~\n\n    std::cout \u003c\u003c \"cache size = \" \u003c\u003c cache.size() \u003c\u003c '\\n'; // 2\n    cache.clear();\n\n    std::cout \u003c\u003c \"cache size = \" \u003c\u003c cache.size() \u003c\u003c '\\n'; // 0\n    return 0;\n\n    // 注意, 如果是c++14及其以后\n    // 如果key是std::string, \n    // 那么当我们使用 cache.get(\"KeyData\"); 的时候,\n    // 使用的是`透明查找`! 不会原地调用`std::string`的构造函数把`const char *`\n    // 构造后, 再传参! 而是直接使用\n    // 例如: XxxCache::get\u003cchar [8]\u003e(const char (\u0026key)[8]) 这个方法\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhengxin666%2Fhxcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhengxin666%2Fhxcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhengxin666%2Fhxcache/lists"}