{"_id":"@alloc/quick-lru","_rev":"2959697","name":"@alloc/quick-lru","description":"Simple “Least Recently Used” (LRU) cache","dist-tags":{"latest":"5.2.0"},"maintainers":[{"name":"aleclarson","email":"alec.stanford.larson@gmail.com"}],"time":{"modified":"2023-04-28T06:16:48.000Z","created":"2021-04-06T00:28:18.669Z","5.2.0":"2021-04-06T00:28:18.669Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/quick-lru.git"},"versions":{"5.2.0":{"name":"@alloc/quick-lru","version":"5.2.0","description":"Simple “Least Recently Used” (LRU) cache","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/quick-lru.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"engines":{"node":">=10"},"scripts":{"test":"xo && nyc ava && tsd"},"keywords":["lru","quick","cache","caching","least","recently","used","fast","map","hash","buffer"],"devDependencies":{"ava":"^2.0.0","coveralls":"^3.0.3","nyc":"^15.0.0","tsd":"^0.11.0","xo":"^0.26.0"},"gitHead":"73f6da4abbf081e8dd885405bd0a2c645c3a5eed","bugs":{"url":"https://github.com/sindresorhus/quick-lru/issues"},"homepage":"https://github.com/sindresorhus/quick-lru#readme","_id":"@alloc/quick-lru@5.2.0","_nodeVersion":"14.13.1","_npmVersion":"6.14.8","dist":{"shasum":"7bf68b20c0a350f936915fcae06f58e32007ce30","size":4465,"noattachment":false,"key":"/@alloc/quick-lru/-/@alloc/quick-lru-5.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@alloc/quick-lru/download/@alloc/quick-lru-5.2.0.tgz"},"_npmUser":{"name":"aleclarson","email":"aleclarson@protonmail.com"},"directories":{},"maintainers":[{"name":"aleclarson","email":"alec.stanford.larson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/quick-lru_5.2.0_1617668898547_0.8839094547660911"},"_hasShrinkwrap":false,"publish_time":1617668898669,"_cnpm_publish_time":1617668898669,"_cnpmcore_publish_time":"2021-12-16T14:49:08.748Z"}},"readme":"# quick-lru [![Build Status](https://travis-ci.org/sindresorhus/quick-lru.svg?branch=master)](https://travis-ci.org/sindresorhus/quick-lru) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/quick-lru/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/quick-lru?branch=master)\n\n> Simple [“Least Recently Used” (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29)\n\nUseful when you need to cache something and limit memory usage.\n\nInspired by the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm), but instead uses [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) to support keys of any type, not just strings, and values can be `undefined`.\n\n## Install\n\n```\n$ npm install quick-lru\n```\n\n## Usage\n\n```js\nconst QuickLRU = require('quick-lru');\n\nconst lru = new QuickLRU({maxSize: 1000});\n\nlru.set('????', '????');\n\nlru.has('????');\n//=> true\n\nlru.get('????');\n//=> '????'\n```\n\n## API\n\n### new QuickLRU(options?)\n\nReturns a new instance.\n\n### options\n\nType: `object`\n\n#### maxSize\n\n*Required*\\\nType: `number`\n\nThe maximum number of items before evicting the least recently used items.\n\n#### maxAge\n\nType: `number`\\\nDefault: `Infinity`\n\nThe maximum number of milliseconds an item should remain in cache.\nBy default maxAge will be Infinity, which means that items will never expire.\n\nLazy expiration happens upon the next `write` or `read` call.\n\nIndividual expiration of an item can be specified by the `set(key, value, options)` method.\n\n#### onEviction\n\n*Optional*\\\nType: `(key, value) => void`\n\nCalled right before an item is evicted from the cache.\n\nUseful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).\n\n### Instance\n\nThe instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.\n\nBoth `key` and `value` can be of any type.\n\n#### .set(key, value, options?)\n\nSet an item. Returns the instance.\n\nIndividual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified on the constructor, otherwise the item will never expire.\n\n#### .get(key)\n\nGet an item.\n\n#### .has(key)\n\nCheck if an item exists.\n\n#### .peek(key)\n\nGet an item without marking it as recently used.\n\n#### .delete(key)\n\nDelete an item.\n\nReturns `true` if the item is removed or `false` if the item doesn't exist.\n\n#### .clear()\n\nDelete all items.\n\n#### .resize(maxSize)\n\nUpdate the `maxSize`, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.\n\nUseful for on-the-fly tuning of cache sizes in live systems.\n\n#### .keys()\n\nIterable for all the keys.\n\n#### .values()\n\nIterable for all the values.\n\n#### .entriesAscending()\n\nIterable for all entries, starting with the oldest (ascending in recency).\n\n#### .entriesDescending()\n\nIterable for all entries, starting with the newest (descending in recency).\n\n#### .size\n\nThe stored item count.\n\n---\n\n<div align=\"center\">\n\t<b>\n\t\t<a href=\"https://tidelift.com/subscription/pkg/npm-quick-lru?utm_source=npm-quick-lru&utm_medium=referral&utm_campaign=readme\">Get professional support for this package with a Tidelift subscription</a>\n\t</b>\n\t<br>\n\t<sub>\n\t\tTidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.\n\t</sub>\n</div>\n","_attachments":{},"homepage":"https://github.com/sindresorhus/quick-lru#readme","bugs":{"url":"https://github.com/sindresorhus/quick-lru/issues"},"license":"MIT"}