{"id":20358347,"url":"https://github.com/serverless-dns/lfu-cache","last_synced_at":"2025-06-20T17:10:36.518Z","repository":{"id":57140101,"uuid":"344507354","full_name":"serverless-dns/lfu-cache","owner":"serverless-dns","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-08T12:54:23.000Z","size":107,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-11T18:32:02.519Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serverless-dns.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":"2021-03-04T14:45:00.000Z","updated_at":"2025-05-08T12:54:26.000Z","dependencies_parsed_at":"2024-11-14T23:28:04.469Z","dependency_job_id":"9b08c7e2-fab1-4e4b-83d1-9f00d37c2ea1","html_url":"https://github.com/serverless-dns/lfu-cache","commit_stats":{"total_commits":90,"total_committers":6,"mean_commits":15.0,"dds":"0.38888888888888884","last_synced_commit":"356b70d178aef3570884084a3d474ff7837c4735"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/serverless-dns/lfu-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-dns%2Flfu-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-dns%2Flfu-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-dns%2Flfu-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-dns%2Flfu-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serverless-dns","download_url":"https://codeload.github.com/serverless-dns/lfu-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-dns%2Flfu-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260985197,"owners_count":23092888,"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":[],"created_at":"2024-11-14T23:26:33.893Z","updated_at":"2025-06-20T17:10:31.495Z","avatar_url":"https://github.com/serverless-dns.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"*Least Frequently Used* cache.\n\n`/strat` contains an approximate implementation of the _Clock_ algorithm, which increments\nfrequency on cache-hits and decrements frequency of items in the same 'clock' where a newer\nentry seeks admission into, which helps avoid starvation. Another algorithm, _O1_ implements\na constant-time LFU-LRU hybrid cache, but the flip side is it consumes extra memory compared\nto _Clock_, though is very much simpler to reason about.\n\n`/ds` contains implementations of underlying stores supporting the cache: A `HashMap` backed\nby the native `Map` impl, and a restrictive `RangeList` backed by a Skip List.\n\nThat is, `Clock.js`, `MultiClock.js`, `O1.js` instances can be backed by either `HashMap`\nfor point queries (takes ~500ms for 1M point-queries), or by `RangeList` for range queries\n(takes ~5000ms for 1M range queries; see the [`perf workflow`](https://github.com/serverless-dns/lfu-cache/actions/workflows/perf.yml)).\n\n`lfu.js` serves as the entrypoint to construct and interact with these LFUs.\n\n```js\n  import { LfuCache, RangeLfu } from \"@serverless-dns/lfu.js\";\n\n  const lfu = new LfuCache(\"L1\", 10)\n  lfu.put(1, \"a\") // 1 -\u003e \"a\"\n  const v = lfu.get(1) // v = \"a\"\n\n  const rgcache = new RangeLfu(\"R1\", 10)\n  rgcache.put(1, 10, \"a\") // (1, 10) -\u003e \"a\"\n  const v = rgcache.get(5) // v = \"a\"\n````\n\n\u003e All caches are magic. Knowing their mechanism is not enough to predict their outcome.\n\u003e\n\u003e \\- [Avery Pennarun](https://apenwarr.ca/log/20230415).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless-dns%2Flfu-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserverless-dns%2Flfu-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless-dns%2Flfu-cache/lists"}