{"id":13671627,"url":"https://github.com/arthurprs/quick-cache","last_synced_at":"2026-03-27T02:43:31.230Z","repository":{"id":56725235,"uuid":"523502789","full_name":"arthurprs/quick-cache","owner":"arthurprs","description":"Lightweight and high performance concurrent cache","archived":false,"fork":false,"pushed_at":"2026-03-19T16:00:01.000Z","size":283,"stargazers_count":330,"open_issues_count":4,"forks_count":29,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-03-20T08:06:09.494Z","etag":null,"topics":["cache","caching","clock-pro","concurrent","lru","rust","s3-fifo"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arthurprs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2022-08-10T21:32:35.000Z","updated_at":"2026-03-19T15:59:23.000Z","dependencies_parsed_at":"2024-01-09T22:31:29.471Z","dependency_job_id":"e637091d-0a86-4d17-80f3-812176c3df41","html_url":"https://github.com/arthurprs/quick-cache","commit_stats":{"total_commits":32,"total_committers":2,"mean_commits":16.0,"dds":0.09375,"last_synced_commit":"5b01b9a177e3b38d18aa6d84ad7ad31b7c79b964"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/arthurprs/quick-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurprs%2Fquick-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurprs%2Fquick-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurprs%2Fquick-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurprs%2Fquick-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arthurprs","download_url":"https://codeload.github.com/arthurprs/quick-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurprs%2Fquick-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31011693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T02:33:22.146Z","status":"ssl_error","status_checked_at":"2026-03-27T02:33:21.763Z","response_time":164,"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":["cache","caching","clock-pro","concurrent","lru","rust","s3-fifo"],"created_at":"2024-08-02T09:01:14.888Z","updated_at":"2026-03-27T02:43:31.217Z","avatar_url":"https://github.com/arthurprs.png","language":"Rust","readme":"# Quick Cache\n\n[![Crates.io](https://img.shields.io/crates/v/quick_cache.svg)](https://crates.io/crates/quick_cache)\n[![Docs](https://docs.rs/quick_cache/badge.svg)](https://docs.rs/quick_cache/latest)\n[![CI](https://github.com/arthurprs/quick-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/arthurprs/quick-cache/actions/workflows/ci.yml)\n\nLightweight and high performance concurrent cache optimized for low cache overhead.\n\n* Small overhead compared to a concurrent hash table\n* Scan resistant and high hit rate caching policy (S3-FIFO)\n* User defined weight per item\n* Scales well with the number of threads\n* Atomic operations with `get_or_insert` and `get_value_or_guard` functions\n* Atomic async operations with `get_or_insert_async` and `get_value_or_guard_async` functions\n* Closure-based `entry` API for atomic inspect-and-act patterns (keep, remove, replace)\n* Supports item pinning\n* Iteration and draining\n* Handles zero weight items efficiently\n* Allows for customizable lifecycle hooks (e.g. can be used to implement eviction listeners)\n* Doesn't use background threads\n* Only trivially verifiable usages of unsafe\n* Small dependency tree\n\nThe implementation is optimized for use cases where the cache access times and overhead can add up to be a significant cost.\nFeatures like: time to live, event listeners and others; are partially or not implemented in Quick Cache.\nIf you need these features you may want to take a look at the [Moka](https://crates.io/crates/moka) crate.\n\n## Examples\n\nBasic usage\n\n```rust\nuse quick_cache::unsync::Cache;\n\nfn main() {\n    let mut cache = Cache::new(5);\n    cache.insert(\"square\", \"blue\");\n    cache.insert(\"circle\", \"black\");\n    assert_eq!(*cache.get(\u0026\"square\").unwrap(), \"blue\");\n    assert_eq!(*cache.get(\u0026\"circle\").unwrap(), \"black\");\n}\n```\n\nA cache with custom item weights. In this case according to the string length of the value.\n\n```rust\nuse quick_cache::{Weighter, sync::Cache};\n\n#[derive(Clone)]\nstruct StringWeighter;\n\nimpl Weighter\u003cu64, String\u003e for StringWeighter {\n    fn weight(\u0026self, _key: \u0026u64, val: \u0026String) -\u003e u64 {\n        // Be cautious about zero weights!\n        val.len() as u64\n    }\n}\n\nfn main() {\n    let cache = Cache::with_weighter(100, 100_000, StringWeighter);\n    cache.insert(1, \"1\".to_string());\n    cache.insert(54, \"54\".to_string());\n    cache.insert(1000, \"1000\".to_string());\n    assert_eq!(cache.get(\u00261000).unwrap(), \"1000\");\n}\n```\n\nAtomic inspect-and-act with the `entry` API\n\n```rust\nuse quick_cache::sync::{Cache, EntryAction, EntryResult};\n\nfn main() {\n    let cache: Cache\u003cu64, u64\u003e = Cache::new(100);\n\n    // Insert-or-get: if absent, compute and insert; if present, return cached\n    let result = cache.entry(\u00260, None, |_key, val| EntryAction::Retain(*val));\n    let value = match result {\n        EntryResult::Retained(v) =\u003e v,\n        EntryResult::Vacant(guard) =\u003e {\n            let v = 42; // expensive computation\n            guard.insert(v).unwrap();\n            v\n        }\n        _ =\u003e unreachable!(),\n    };\n    assert_eq!(value, 42);\n\n    // Conditionally remove: evict entries below a threshold\n    let result = cache.entry(\u00260, None, |_key, val| {\n        if *val \u003c 100 {\n            EntryAction::\u003c()\u003e::Remove\n        } else {\n            EntryAction::Retain(())\n        }\n    });\n    assert!(matches!(result, EntryResult::Removed(0, 42)));\n}\n```\n\nUsing the `Equivalent` trait for complex keys\n\n```rust\nuse quick_cache::{sync::Cache, Equivalent};\n\n#[derive(Debug, Hash)]\npub struct Pair\u003cA, B\u003e(pub A, pub B);\n\nimpl\u003cA, B, C, D\u003e Equivalent\u003c(C, D)\u003e for Pair\u003cA, B\u003e\nwhere\n    A: PartialEq\u003cC\u003e,\n    B: PartialEq\u003cD\u003e,\n{\n    fn equivalent(\u0026self, rhs: \u0026(C, D)) -\u003e bool {\n        self.0 == rhs.0 \u0026\u0026 self.1 == rhs.1\n    }\n}\n\nfn main() {\n    let cache: Cache\u003c(String, i32), String\u003e = Cache::new(5);\n    cache.insert((\"square\".to_string(), 2022), \"blue\".to_string());\n    cache.insert((\"square\".to_string(), 2023), \"black\".to_string());\n    assert_eq!(cache.get(\u0026Pair(\"square\", 2022)).unwrap(), \"blue\");\n}\n```\n\n## Benchmarks\n\nSince this crate is performance oriented it needs some comparisons.\nThat said, benchmarks can be misleading so take everything with a pinch of salt.\n\nBenchmarks performed with [mokabench](https://github.com/moka-rs/mokabench) in a x64 Linux OS + Intel i9-12900H CPU.\n\n### Trace 1 (S3 from the Arc paper)\n\n| Cache | Max Capacity | Clients | Inserts | Reads | Hit Ratio | Duration Secs |\n|---|---|---|---|---|---|---|\n| **QuickCache**  | 100000 | 1 | 14300769 | 16407702 | 12.841 | 2.196 |\n| **QuickCache**  | 100000 | 3 | 14301124 | 16407702 | 12.839 | 1.279 |\n| **QuickCache**  | 100000 | 6 | 14300809 | 16407702 | 12.841 | 0.798 |\n| LRU+Mutex | 100000 | 1 | 16025830 | 16407702 | 2.327 | 2.422 |\n| TinyUFO | 100000 | 1 | 15685351 | 16407702 | 4.403 | 11.641 |\n| TinyUFO | 100000 | 3 | 15900217 | 16407702 | 3.093 | 8.828 |\n| TinyUFO | 100000 | 6 | 15918936 | 16407702 | 2.979 | 8.104 |\n| Mini Moka  | 100000 | 1 | 14695340 | 16407702 | 10.436 | 9.399 |\n| Mini Moka  | 100000 | 3 | 14679119 | 16407702 | 10.535 | 8.490 |\n| Mini Moka  | 100000 | 6 | 14706822 | 16407702 | 10.366 | 8.064 |\n| **QuickCache**  | 400000 | 1 | 9435745 | 16407702 | 42.492 | 2.537 |\n| **QuickCache**  | 400000 | 3 | 9437141 | 16407702 | 42.483 | 1.323 |\n| **QuickCache**  | 400000 | 6 | 9436549 | 16407702 | 42.487 | 0.899 |\n| LRU+Mutex | 400000 | 1 | 14432404 | 16407702 | 12.039 | 2.766 |\n| TinyUFO | 400000 | 1 | 11455971 | 16407702 | 30.179 | 14.234 |\n| TinyUFO | 400000 | 3 | 12405638 | 16407702 | 24.391 | 8.695 |\n| TinyUFO | 400000 | 6 | 12551335 | 16407702 | 23.503 | 7.008 |\n| Mini Moka  | 400000 | 1 | 9427172 | 16407702 | 42.544 | 8.511 |\n| Mini Moka  | 400000 | 3 | 9584914 | 16407702 | 41.583 | 6.624 |\n| Mini Moka  | 400000 | 6 | 9656084 | 16407702 | 41.149 | 6.613 |\n| **QuickCache**  | 800000 | 1 | 5184786 | 16407702 | 68.400 | 3.207 |\n| **QuickCache**  | 800000 | 3 | 5185210 | 16407702 | 68.398 | 1.353 |\n| **QuickCache**  | 800000 | 6 | 5185337 | 16407702 | 68.397 | 0.743 |\n| LRU+Mutex | 800000 | 1 | 7120978 | 16407702 | 56.600 | 2.613 |\n| TinyUFO | 800000 | 1 | 5598215 | 16407702 | 65.881 | 10.043 |\n| TinyUFO | 800000 | 3 | 6007956 | 16407702 | 63.383 | 5.077 |\n| TinyUFO | 800000 | 6 | 6071806 | 16407702 | 62.994 | 3.789 |\n| Mini Moka  | 800000 | 1 | 4872358 | 16407702 | 70.304 | 8.574 |\n| Mini Moka  | 800000 | 3 | 5012764 | 16407702 | 69.449 | 5.363 |\n| Mini Moka  | 800000 | 6 | 5529311 | 16407702 | 66.301 | 4.551 |\n\n### Trace 2 (DS1 from the Arc paper)\n\n| Cache | Max Capacity | Clients | Inserts | Reads | Hit Ratio | Duration Secs |\n|---|---|---|---|---|---|---|\n| **QuickCache**  | 1000000 | 1 | 37208683 | 43704979 | 14.864 | 9.883 |\n| **QuickCache**  | 1000000 | 3 | 37196302 | 43704979 | 14.892 | 4.546 |\n| **QuickCache**  | 1000000 | 6 | 37196402 | 43704979 | 14.892 | 3.585 |\n| LRU+Mutex | 1000000 | 1 | 42356290 | 43704979 | 3.086 | 8.901 |\n| TinyUFO | 1000000 | 1 | 42093670 | 43704979 | 3.687 | 60.135 |\n| TinyUFO | 1000000 | 3 | 42203137 | 43704979 | 3.436 | 35.306 |\n| TinyUFO | 1000000 | 6 | 42214889 | 43704979 | 3.409 | 25.440 |\n| Mini Moka  | 1000000 | 1 | 37188446 | 43704979 | 14.910 | 25.833 |\n| Mini Moka  | 1000000 | 3 | 37332123 | 43704979 | 14.582 | 23.078 |\n| Mini Moka  | 1000000 | 6 | 38104018 | 43704979 | 12.815 | 23.571 |\n| **QuickCache**  | 4000000 | 1 | 24156843 | 43704979 | 44.727 | 9.497 |\n| **QuickCache**  | 4000000 | 3 | 24159591 | 43704979 | 44.721 | 4.257 |\n| **QuickCache**  | 4000000 | 6 | 24204044 | 43704979 | 44.619 | 2.777 |\n| LRU+Mutex | 4000000 | 1 | 34856997 | 43704979 | 20.245 | 10.735 |\n| TinyUFO | 4000000 | 1 | 32607709 | 43704979 | 25.391 | 49.380 |\n| TinyUFO | 4000000 | 3 | 32810383 | 43704979 | 24.928 | 26.440 |\n| TinyUFO | 4000000 | 6 | 32840752 | 43704979 | 24.858 | 20.390 |\n| Mini Moka  | 4000000 | 1 | 23863892 | 43704979 | 45.398 | 26.103 |\n| Mini Moka  | 4000000 | 3 | 23865870 | 43704979 | 45.393 | 19.896 |\n| Mini Moka  | 4000000 | 6 | 25152629 | 43704979 | 42.449 | 17.912 |\n| **QuickCache**  | 8000000 | 1 | 13405437 | 43704979 | 69.327 | 7.703 |\n| **QuickCache**  | 8000000 | 3 | 13406862 | 43704979 | 69.324 | 3.598 |\n| **QuickCache**  | 8000000 | 6 | 13406780 | 43704979 | 69.324 | 2.243 |\n| LRU+Mutex | 8000000 | 1 | 24896662 | 43704979 | 43.035 | 8.995 |\n| TinyUFO | 8000000 | 1 | 20143204 | 43704979 | 53.911 | 28.245 |\n| TinyUFO | 8000000 | 3 | 20339486 | 43704979 | 53.462 | 14.967 |\n| TinyUFO | 8000000 | 6 | 20364270 | 43704979 | 53.405 | 11.206 |\n| Mini Moka  | 8000000 | 1 | 14227354 | 43704979 | 67.447 | 29.082 |\n| Mini Moka  | 8000000 | 3 | 13762562 | 43704979 | 68.510 | 17.060 |\n| Mini Moka  | 8000000 | 6 | 14926093 | 43704979 | 65.848 | 12.294 |\n\n### Trace 3 (SPC1 from the Arc paper)\n\n| Cache | Max Capacity | Clients | Inserts | Reads | Hit Ratio | Duration Secs |\n|---|---|---|---|---|---|---|\n| **QuickCache**  | 500000 | 1 | 36994843 | 41351279 | 10.535 | 7.880 |\n| LRU+Mutex | 500000 | 1 | 39942249 | 41351279 | 3.407 | 9.820 |\n| TinyUFO | 500000 | 1 | 39197208 | 41351279 | 5.209 | 49.395 |\n| Mini Moka  | 500000 | 1 | 36231669 | 41351279 | 12.381 | 25.467 |\n| **QuickCache**  | 2000000 | 1 | 24123918 | 41351279 | 41.661 | 14.611 |\n| LRU+Mutex | 2000000 | 1 | 30181071 | 41351279 | 27.013 | 10.768 |\n| TinyUFO | 2000000 | 1 | 27173449 | 41351279 | 34.286 | 46.476 |\n| Mini Moka  | 2000000 | 1 | 24032624 | 41351279 | 41.882 | 31.064 |\n| **QuickCache**  | 30000000 | 1 | 6050363 | 41351279 | 85.368 | 8.170 |\n| LRU+Mutex | 30000000 | 1 | 6050363 | 41351279 | 85.368 | 8.594 |\n| TinyUFO | 30000000 | 1 | 6050363 | 41351279 | 85.368 | 14.065 |\n| Mini Moka  | 30000000 | 1 | 6050363 | 41351279 | 85.368 | 34.452 |\n\nNotes:\n\n* LRU+Mutex: hashlink crate + std::sync::Mutex\n* SPC1 only includes 1 client to save space, it follows the same trend as other traces.\n* Other Moka variants not included to save space, they perform similarly or worse than Mini Moka. [Full results](https://github.com/arthurprs/quick-cache/issues/49#issuecomment-2323322103)\n\n## References\n\n* [CLOCK-Pro: An Effective Improvement of the CLOCK Replacement (pdf)](https://www.usenix.org/legacy/events/usenix05/tech/general/full_papers/jiang/jiang.pdf)\n* [FIFO queues are all you need for cache eviction (pdf)](https://dl.acm.org/doi/10.1145/3600006.3613147)\n* [Caffeine (source code)](https://github.com/ben-manes/caffeine)\n* [Cache2k (source code)](https://github.com/cache2k/cache2k)\n\n## License\n\nThis project is licensed under the MIT license.\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurprs%2Fquick-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farthurprs%2Fquick-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurprs%2Fquick-cache/lists"}