{"_id":"@alloc/quick-lru","_rev":"3-2a0c4b34ab99b92845b04716825b345d","name":"@alloc/quick-lru","dist-tags":{"latest":"5.3.0"},"versions":{"5.2.0":{"name":"@alloc/quick-lru","version":"5.2.0","keywords":["lru","quick","cache","caching","least","recently","used","fast","map","hash","buffer"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"@alloc/quick-lru@5.2.0","maintainers":[{"name":"aleclarson","email":"aleclarson@protonmail.com"}],"homepage":"https://github.com/sindresorhus/quick-lru#readme","bugs":{"url":"https://github.com/sindresorhus/quick-lru/issues"},"dist":{"shasum":"7bf68b20c0a350f936915fcae06f58e32007ce30","tarball":"https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz","fileCount":5,"integrity":"sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw==","signatures":[{"sig":"MEUCIAGbPdEPixVJQACokSA1qIsceyVA9O4ya5yo9tFOBHe2AiEA6a7o92d0HLq9FzrUif7JRc9Uaw6NpgEPrSaNwKd/628=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14099,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJga6sjCRA9TVsSAnZWagAA/pEP/0y6cdGEoUIqYYfBiFQ9\nkblkmT9wU9jIFMWnrb4mQSjpFW4CyUgx0dAKnh72Wm0qrObNLdIf/xx7i2L+\nYxKT35Hb3H9N0iEaYswXhU032Soi/QRbRHMeJlupIZd/4yIHB5AyCW+4Bwsx\n9Z1D4Ai9SAlYHb7Uz/IUPWgZf5Bsg1MdL2IVBcwy20fisRlXfQIGIJI6K2N0\nbhCrH7mQF6yG1/5IGCrunO8dcBP8TZ3n0U3k9oGVAu005qPiBuLXT/Cl2w01\nCLKvFTlWCSJrOJh3UyQE3OQebjXwMjJ1ixSiWINt0tqKPpw1gf2JTD3EEa5g\nxJwqmGb1bZc87q+HkruhnCx1B5MCmJmWU9Yby5LeUYRecu6eVFmQC3IWKr/p\ny5TsafBxkDbCCiir11eaNKLeJB5jnHkCk3wog+/ypK7Mpy7gFHSt7ddeKZ1/\nXXw0VrfdlL1oWk/5QWcRdT3JH16IJXJ0fvfVTUq4qe/jYcmduwfgARzJcXrq\nPaaxT+ydyaPZ6BPtHVvzERSA46X+cMtvC34laOydad3ZJj9XOyviu6THsOgl\nqQlv0mEIWKcu87cLh2Z86Di6GsSijp0wU66UG4usm8Pf/clcTCcB5OSRfzgK\niagvWy4eyAKJ1N48jr8B5ol3oYnn9i6lovGuOT1IbW40XYyik5/zCGZFq+G2\nfxOJ\r\n=jseG\r\n-----END PGP SIGNATURE-----\r\n"},"engines":{"node":">=10"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"73f6da4abbf081e8dd885405bd0a2c645c3a5eed","scripts":{"test":"xo && nyc ava && tsd"},"_npmUser":{"name":"aleclarson","email":"aleclarson@protonmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/quick-lru.git","type":"git"},"_npmVersion":"6.14.8","description":"Simple “Least Recently Used” (LRU) cache","directories":{},"_nodeVersion":"14.13.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.26.0","ava":"^2.0.0","nyc":"^15.0.0","tsd":"^0.11.0","coveralls":"^3.0.3"},"_npmOperationalInternal":{"tmp":"tmp/quick-lru_5.2.0_1617668898547_0.8839094547660911","host":"s3://npm-registry-packages"}},"5.3.0":{"_id":"@alloc/quick-lru@5.3.0","bugs":{"url":"https://github.com/aleclarson/quick-lru/issues"},"dist":{"shasum":"9073d52ad3cebbedd0d8c9f3e65aa5527fabd1e0","tarball":"https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.3.0.tgz","fileCount":5,"integrity":"sha512-U4+70Pc5ZS9osnCBCE5Jha/ciHM+Yp+CNMNC/7HvYbNRk1Ldd+f7qO65W5qfhu/TCv+/ozljlXXe9Nj8419DMA==","signatures":[{"sig":"MEYCIQCE/VPv8/VFbk4gQs2ayyyEWqfGf7w9akpux2OMvV1rTwIhAIdY+SY7kkIxIQKnbyaBIX+c3YPx0V/v9oeCVXPlE1hZ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCiJEhQXw+7h39Ury3Wvx/Ep2dNUuXs3mJcJaHmZRxtZAIhAICu5tFXagc9aTinkH9dVJvEEJ1p8TUbdsdr3EmGK9hj"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@alloc%2fquick-lru@5.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":16601},"name":"@alloc/quick-lru","types":"./index.d.ts","author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"engines":{"node":">=10"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"49a87e835c6e657d0df87a031e88d1e0342e6c30","license":"MIT","scripts":{"test":"xo && nyc ava && tsd"},"version":"5.3.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ea1ff5fb-df67-41eb-9f76-7de73e412fbd"}},"homepage":"https://github.com/aleclarson/quick-lru#readme","keywords":["lru","quick","cache","caching","least","recently","used","fast","map","hash","buffer"],"repository":{"url":"git+https://github.com/aleclarson/quick-lru.git","type":"git"},"_npmVersion":"11.19.0","description":"Simple “Least Recently Used” (LRU) cache","directories":{},"maintainers":[{"name":"aleclarson","email":"alec.stanford.larson@gmail.com"}],"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.26.0","ava":"^2.0.0","nyc":"^15.0.0","tsd":"^0.11.0","coveralls":"^3.0.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/quick-lru_5.3.0_1788197250637_0.29753073019355325"}}},"time":{"created":"2021-04-06T00:28:18.367Z","modified":"2026-08-31T17:27:31.076Z","5.2.0":"2021-04-06T00:28:18.669Z","5.3.0":"2026-08-31T17:27:30.730Z"},"bugs":{"url":"https://github.com/aleclarson/quick-lru/issues"},"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","homepage":"https://github.com/aleclarson/quick-lru#readme","keywords":["lru","quick","cache","caching","least","recently","used","fast","map","hash","buffer"],"repository":{"url":"git+https://github.com/aleclarson/quick-lru.git","type":"git"},"description":"Simple “Least Recently Used” (LRU) cache","maintainers":[{"name":"aleclarson","email":"alec.stanford.larson@gmail.com"}],"readme":"# @alloc/quick-lru [![Build Status](https://travis-ci.org/aleclarson/quick-lru.svg?branch=master)](https://travis-ci.org/aleclarson/quick-lru) [![Coverage Status](https://coveralls.io/repos/github/aleclarson/quick-lru/badge.svg?branch=master)](https://coveralls.io/github/aleclarson/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\nThis is a CommonJS-only fork of [`quick-lru`](https://github.com/sindresorhus/quick-lru).\n\nUseful when you need to cache something and limit memory usage.\n\nSee the [algorithm section](#algorithm) for implementation details.\n\n## Install\n\n```\n$ npm install @alloc/quick-lru\n```\n\n## Usage\n\n```js\nconst QuickLRU = require('@alloc/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 target maximum number of items before evicting the least recently used items.\n\n> **Note:** The dual-cache algorithm may physically retain up to twice `maxSize` entries for performance reasons, even though the reported cache size does not exceed `maxSize`.\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 due to capacity pressure or TTL expiration.\n\nUseful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).\n\nThis callback is not called for manual removals via `delete()` or `clear()`.\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#### .expiresIn(key)\n\nGet the remaining time to live (in milliseconds) for the given item, or `undefined` if the item is not in the cache.\n\n- Does not mark the item as recently used.\n- Does not trigger lazy expiration or remove the entry when it is expired.\n- Returns `Infinity` if the item has no expiration.\n- May return a negative number if the item has already expired but has not yet been lazily removed.\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## Algorithm\n\nThis library implements a variant of the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm) using two [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) objects. One map holds recently added or accessed entries, while the other holds older entries. When the recent map reaches `maxSize`, it replaces the older map and a new recent map is created.\n\nThis avoids the frequent delete operations required by a traditional linked-list LRU and supports keys of any type and `undefined` values. The tradeoff is that the two maps may physically retain up to twice the target `maxSize` between rotations. Use a strict-size cache when that temporary memory overhead is unacceptable.\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","readmeFilename":"readme.md"}