{"id":13527272,"url":"https://github.com/node-modules/ylru","last_synced_at":"2025-04-01T09:31:20.382Z","repository":{"id":15118993,"uuid":"77580415","full_name":"node-modules/ylru","owner":"node-modules","description":"Add \"expire\", \"allow set empty value\" extends on hashlru","archived":false,"fork":true,"pushed_at":"2024-03-28T03:58:18.000Z","size":48,"stargazers_count":40,"open_issues_count":0,"forks_count":4,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-04-14T13:37:55.411Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"dominictarr/hashlru","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-modules.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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":"2016-12-29T03:42:03.000Z","updated_at":"2024-03-28T03:58:43.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/node-modules/ylru","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fylru","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fylru/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fylru/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fylru/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-modules","download_url":"https://codeload.github.com/node-modules/ylru/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246591782,"owners_count":20801984,"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-08-01T06:01:44.557Z","updated_at":"2025-04-01T09:31:20.051Z","avatar_url":"https://github.com/node-modules.png","language":"JavaScript","readme":"# ylru\n\n[![NPM version][npm-image]][npm-url]\n[![Node.js CI](https://github.com/node-modules/ylru/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/ylru/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/ylru.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ylru\n[codecov-image]: https://img.shields.io/codecov/c/github/node-modules/ylru.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/node-modules/ylru?branch=master\n[snyk-image]: https://snyk.io/test/npm/ylru/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/ylru\n[download-image]: https://img.shields.io/npm/dm/ylru.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ylru\n\n**hashlru inspired**\n\n[hashlru](https://github.com/dominictarr/hashlru) is the **Simpler, faster LRU cache algorithm.**\nPlease checkout [algorithm](https://github.com/dominictarr/hashlru#algorithm) and [complexity](https://github.com/dominictarr/hashlru#complexity) on hashlru.\n\nylru extends some features base on hashlru:\n\n- cache value can be **expired**.\n- cache value can be **empty value**, e.g.: `null`, `undefined`, `''`, `0`\n\n## Usage\n\n```ts\nimport { LRU } from 'ylru';\n\nconst lru = new LRU(100);\nlru.set(key, value);\nlru.get(key);\n\n// value2 will be expired after 5000ms\nlru.set(key2, value2, { maxAge: 5000 });\n// get key and update expired\nlru.get(key2, { maxAge: 5000 });\n```\n\n### API\n\n## new LRU(max) =\u003e lru\n\ninitialize a lru object.\n\n### lru.get(key[, options]) =\u003e value | null\n\n- `{Number} options.maxAge`: update expire time when get, value will become `undefined` after `maxAge` pass.\n\nReturns the value in the cache.\n\n### lru.set(key, value[, options])\n\n- `{Number} options.maxAge`: value will become `undefined` after `maxAge` pass.\nIf `maxAge` not set, value will be never expired.\n\nSet the value for key.\n\n### lru.keys()\n\nGet all unexpired cache keys from lru, due to the strategy of ylru, the `keys`' length may greater than `max`.\n\n```ts\nconst lru = new LRU(3);\n\nlru.set('key 1', 'value 1');\nlru.set('key 2', 'value 2');\nlru.set('key 3', 'value 3');\nlru.set('key 4', 'value 4');\n\nlru.keys(); // [ 'key 4', 'key 1', 'key 2', 'key 3']\n// cache: {\n//   'key 4': 'value 4',\n// }\n// _cache: {\n//   'key 1': 'value 1',\n//   'key 2': 'value 2',\n//   'key 3': 'value 3',\n// }\n```\n\n### lru.reset()\n\nreset a lru object.\n\n```ts\nconst lru = new LRU(3);\n\nlru.set('key 1', 'value 1');\nlru.set('key 2', 'value 2');\nlru.set('key 3', 'value 3');\nlru.set('key 4', 'value 4');\n\nlru.reset();\n// cache: {\n// }\n// _cache: {\n// }\n\nlru.keys().length === 0;\n```\n\n## License\n\n[MIT](LICENSE)\n\n\u003c!-- GITCONTRIBUTOR_START --\u003e\n\n## Contributors\n\n|[\u003cimg src=\"https://avatars.githubusercontent.com/u/156269?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003efengmk2\u003c/b\u003e\u003c/sub\u003e](https://github.com/fengmk2)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/259374?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003edominictarr\u003c/b\u003e\u003c/sub\u003e](https://github.com/dominictarr)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/985607?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003edead-horse\u003c/b\u003e\u003c/sub\u003e](https://github.com/dead-horse)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/958063?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ethonatos\u003c/b\u003e\u003c/sub\u003e](https://github.com/thonatos)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/25395?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003emourner\u003c/b\u003e\u003c/sub\u003e](https://github.com/mourner)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/32174276?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003esemantic-release-bot\u003c/b\u003e\u003c/sub\u003e](https://github.com/semantic-release-bot)\u003cbr/\u003e|\n| :---: | :---: | :---: | :---: | :---: | :---: |\n[\u003cimg src=\"https://avatars.githubusercontent.com/u/6828924?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003evagusX\u003c/b\u003e\u003c/sub\u003e](https://github.com/vagusX)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/566097?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eRaoHai\u003c/b\u003e\u003c/sub\u003e](https://github.com/RaoHai)\u003cbr/\u003e\n\nThis project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Thu Mar 28 2024 11:52:18 GMT+0800`.\n\n\u003c!-- GITCONTRIBUTOR_END --\u003e\n","funding_links":[],"categories":["Repository"],"sub_categories":["Cache"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fylru","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-modules%2Fylru","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fylru/lists"}