{"_id":"@alloc/quick-lru@5.3.0","bugs":{"url":"https://github.com/aleclarson/quick-lru/issues"},"dist":{"shasum":"9073d52ad3cebbedd0d8c9f3e65aa5527fabd1e0","tarball":"http://registry-npm.ywwl.com/@alloc/quick-lru/download/@alloc/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,"size":5169,"noattachment":false,"key":"/@alloc/quick-lru/-/@alloc/quick-lru-5.3.0.tgz"},"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"},"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","publish_time":1788197250730,"_cnpm_publish_time":1788197250730,"dist-tags":{"latest":"5.3.0"}}