{"id":13458244,"url":"https://github.com/vpetrigo/caches","last_synced_at":"2026-02-14T18:07:05.269Z","repository":{"id":43010100,"uuid":"59040861","full_name":"vpetrigo/caches","owner":"vpetrigo","description":"C++ cache with LRU/LFU/FIFO policies implementation","archived":false,"fork":false,"pushed_at":"2026-01-27T00:22:42.000Z","size":2223,"stargazers_count":377,"open_issues_count":6,"forks_count":80,"subscribers_count":16,"default_branch":"master","last_synced_at":"2026-01-27T04:40:36.167Z","etag":null,"topics":["c-plus-plus","cache","cpp","cpp11","fifo","fifo-cache","header-only","lfu","lfu-cache","lru","lru-cache"],"latest_commit_sha":null,"homepage":"http://rs-stuff.dev/caches/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vpetrigo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://boosty.to/vladimir.petrigo"]}},"created_at":"2016-05-17T16:43:53.000Z","updated_at":"2026-01-15T11:27:23.000Z","dependencies_parsed_at":"2025-09-16T13:22:35.649Z","dependency_job_id":null,"html_url":"https://github.com/vpetrigo/caches","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/vpetrigo/caches","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpetrigo%2Fcaches","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpetrigo%2Fcaches/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpetrigo%2Fcaches/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpetrigo%2Fcaches/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vpetrigo","download_url":"https://codeload.github.com/vpetrigo/caches/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpetrigo%2Fcaches/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29452129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["c-plus-plus","cache","cpp","cpp11","fifo","fifo-cache","header-only","lfu","lfu-cache","lru","lru-cache"],"created_at":"2024-07-31T09:00:48.267Z","updated_at":"2026-02-14T18:07:05.264Z","avatar_url":"https://github.com/vpetrigo.png","language":"C++","readme":"[![CI](https://github.com/vpetrigo/caches/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/vpetrigo/caches/actions/workflows/ci.yml)\n[![Build status](https://ci.appveyor.com/api/projects/status/kawd812e48065r7a?svg=true)](https://ci.appveyor.com/project/vpetrigo/caches)\n[![codecov](https://codecov.io/gh/vpetrigo/caches/branch/master/graph/badge.svg?token=uExJPtyE0o)](https://codecov.io/gh/vpetrigo/caches)\n[![version](https://img.shields.io/github/v/release/vpetrigo/caches)](https://github.com/vpetrigo/caches/releases)\n\n# C++ Cache implementation\n\nThis project implements a simple thread-safe cache with several page replacement policies:\n\n* Least Recently Used\n* First-In/First-Out\n* Least Frequently Used\n\nMore about cache algorithms and policy you could read on [Wikipedia](https://en.wikipedia.org/wiki/Cache_algorithms)\n\n# Usage\n\nUsing this library is simple. It is necessary to include header with the cache implementation (`caches/cache.hpp` file)\nand appropriate header with the cache policy if it is needed. If not then the non-special algorithm will be used (it\nremoves the last element which key is the last in the internal container).\n\nCurrently, there is only three of them:\n\n* `fifo_cache_policy.hpp`\n* `lfu_cache_policy.hpp`\n* `lru_cache_policy.hpp`\n\nExample for the LRU policy:\n\n```cpp\n#include \u003cstring\u003e\n#include \"caches/cache.hpp\"\n#include \"caches/lru_cache_policy.hpp\"\n\n// alias for an easy class typing\ntemplate \u003ctypename Key, typename Value\u003e\nusing lru_cache_t = typename caches::fixed_sized_cache\u003cKey, Value, caches::LRUCachePolicy\u003e;\n\nvoid foo() {\n  constexpr std::size_t CACHE_SIZE = 256;\n  lru_cache_t\u003cstd::string, int\u003e cache(CACHE_SIZE);\n\n  cache.Put(\"Hello\", 1);\n  cache.Put(\"world\", 2);\n  \n  const auto hello_value = cache.Get(\"Hello\");\n  const auto world_value = cache.Get(\"world\");\n\n  std::cout \u003c\u003c *hello_value \u003c\u003c *world_value \u003c\u003c '\\n';\n  // \"12\"\n}\n```\n\n## Custom hashmap usage\n\nYou can use a custom hashmap implementation for the `caches::fixed_sized_cache` class which has the same interface\n`std::unordered_map` has.\n\nFor example, you can declare LRU cache type like that:\n\n```cpp\n#include \"caches/cache.hpp\"\n\ntemplate \u003ctypename Key, typename Value\u003e\nusing lru_cache_t = typename caches::fixed_sized_cache\u003cKey, Value, caches::LRUCachePolicy,\n                                                       phmap::node_hash_map\u003cKey, Value\u003e\u003e;\n// ...\nlru_cache_t\u003cstd::string, std::size_t\u003e cache{16};\ncache.Put(\"Hello\", 1);\nstd::cout \u003c\u003c *cache.Get(\"Hello\") \u003c\u003c '\\n';\n```\n\nSee `test` implementation which uses [`parallel-hashmap`](https://github.com/greg7mdp/parallel-hashmap).\n\n# Requirements\n\nThe only requirement is a compatible C++11 compiler.\n\nThis project was tested in the environments listed below:\n\n* MinGW64 ([MSYS2 project](https://msys2.github.io/))\n    * Clang 13.0+\n    * GCC 7+\n* MSVC (VS 2015)\n\nIf you have any issues with the library building, please let me know.\n\n# Contributing\n\nPlease fork this repository and contribute back using [pull requests](https://github.com/vpetrigo/caches/pulls).\nFeatures can be requested using [issues](https://github.com/vpetrigo/caches/issues). All code, comments, and critiques\nare greatly appreciated.\n","funding_links":["https://boosty.to/vladimir.petrigo"],"categories":["Awesome Algorithms","C++"],"sub_categories":["Cache"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpetrigo%2Fcaches","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvpetrigo%2Fcaches","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpetrigo%2Fcaches/lists"}