{"id":15645070,"url":"https://github.com/mafintosh/array-lru","last_synced_at":"2025-08-20T19:23:44.728Z","repository":{"id":57184031,"uuid":"79818353","full_name":"mafintosh/array-lru","owner":"mafintosh","description":"A really fast LRU cache for array items (numeric keys)","archived":false,"fork":false,"pushed_at":"2017-01-24T13:55:34.000Z","size":11,"stargazers_count":57,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T01:34:37.752Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/mafintosh.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}},"created_at":"2017-01-23T15:40:46.000Z","updated_at":"2023-11-08T03:24:40.000Z","dependencies_parsed_at":"2022-09-10T18:22:19.896Z","dependency_job_id":null,"html_url":"https://github.com/mafintosh/array-lru","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafintosh%2Farray-lru","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafintosh%2Farray-lru/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafintosh%2Farray-lru/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafintosh%2Farray-lru/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mafintosh","download_url":"https://codeload.github.com/mafintosh/array-lru/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248703193,"owners_count":21148118,"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-10-03T12:04:19.214Z","updated_at":"2025-04-15T21:34:49.348Z","avatar_url":"https://github.com/mafintosh.png","language":"JavaScript","readme":"# array-lru\n\nA really fast LRU cache for array items (numeric keys)\n\n```\nnpm install array-lru\n```\n\n[![build status](https://travis-ci.org/mafintosh/array-lru.svg?branch=master)](http://travis-ci.org/mafintosh/array-lru)\n\nCredit to [@dominictarr](https://github.com/dominictarr) for telling me about this neat algorithm for LRUs.\n\n## Usage\n\n``` js\nvar alru = require('array-lru')\nvar lru = alru(512) // create a lru that can contain 512 values\n\nlru.set(42, {hello: 'world'})\nconsole.log(lru.get(42)) // {hello: 'world'}\n```\n\nIt works similar to a normal hash table except when a bucket is full it will\nevict the oldest one from the bucket to make room for the new value.\n\n## API\n\n#### `var lru = alru(size, [options])`\n\nCreate a new LRU instance. Options include:\n\n``` js\n{\n  collisions: 4, // how many hash collisions before evicting (default 4)\n  evict: fn, // call this function with (index, value) when someone is evicted\n  indexedValues: false // set to true if your values has a .index property\n}\n```\n\nSize should be a multiple of `collisions`. If not, it will be coerced into one.\n\n### `var value = lru.get(index)`\n\nGet a value from the cache. If the index is not found, `null` is returned.\n\n### `lru.set(index, value)`\n\nInsert a new value in the cache. If there is no room in the hash bucket that\n`index` maps to, the oldest value in the bucket will be evicted.\n\n### Performance\n\nOn my MacBook 12\" I can set/get around 7.500.000 values per second, YMMV.\nRun the benchmark using `npm run bench` to test it for yourself.\n\n## License\n\nMIT\n","funding_links":[],"categories":["Utilities"],"sub_categories":["React Components"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmafintosh%2Farray-lru","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmafintosh%2Farray-lru","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmafintosh%2Farray-lru/lists"}