{"name":"tiny-lru","description":"Tiny LRU cache for Client or Server","version":"10.0.0","homepage":"https://github.com/avoidwork/tiny-lru","author":{"name":"Jason Mulligan","email":"jason.mulligan@avoidwork.com"},"repository":{"type":"git","url":"git://github.com/avoidwork/tiny-lru.git"},"bugs":{"url":"https://github.com/avoidwork/tiny-lru/issues"},"license":"BSD-3-Clause","source":"src/lru.js","main":"dist/tiny-lru.cjs","module":"dist/tiny-lru.esm.js","type":"module","sourceType":"module","types":"lru.d.ts","engines":{"node":">=6"},"engineStrict":true,"scripts":{"build":"npm run lint && rm -rf dist/* && npm run rollup && npm run mocha","benchmark":"node benchmark.js","changelog":"auto-changelog -p","lint":"eslint *.js src/*.js test/*.js","mocha":"mocha test/*.js","rollup":"rollup --config","test":"npm run lint && npm run mocha","test-webpack":"rm -rf test/webpack && git clone git@github.com:rabelais88/typescript-webpack.git test/webpack && echo \"import { lru } from 'tiny-lru';console.log(lru(1));\" >> test/webpack/src/index.ts && cd test/webpack && npm install && mkdir -p node_modules/tiny-lru/dist && cp ../../package.json node_modules/tiny-lru/ && cp ../../dist/* node_modules/tiny-lru/dist/ && npm run build","types":"npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir ."},"devDependencies":{"auto-changelog":"^2.4.0","eslint":"^8.23.1","mocha":"^10.0.0","precise":"^2.0.0","rollup":"^2.79.0","rollup-plugin-terser":"^7.0.2","typescript":"^4.8.3"},"keywords":["LRU","cache","tiny","client","server","least","recently","used"],"gitHead":"5fdd1395581d26c1148fce538e4af52bb6e91c63","_id":"tiny-lru@10.0.0","_nodeVersion":"18.8.0","_npmVersion":"8.18.0","dist":{"integrity":"sha512-WAJgx3780wGkPlfXM8ezc9XnX+hodoL0n37f/c+X7/y75pqTkAOTZnxRLiTElkQyhlZ4Qn5FPSgKzachfPD2FA==","shasum":"cf6e5bb23d5ce4720a08fcbd7151fe94ab0b39e6","tarball":"http://registry-npm.ywwl.com/tiny-lru/download/tiny-lru-10.0.0.tgz","fileCount":11,"unpackedSize":29016,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH6cuACLQTiuIJmKZkNQNZPSMQ1Nyjx3SgtpAa219IoiAiAvxfX/NcszQXiXefQd30YN0Y7xr2fVeylcZLntCB2RwQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjWzVYACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrATg/+OG4Q3WhBAjzHpSv1nGuA116MctuKEmGeReWVBGodDD/iG+OV\r\nVBaH1xJvYFEbu5RyBNPzav/hcHMwepoAGUmiMhUVDGpOdjVcIkV2+nkwjpoR\r\nDI+XCxdYFhhYtuULdeYDwWy1jiLf3+hGgp6O9TpVHp27Yavhp4rzMcXoyLu8\r\nB0rLcBY2tAV3XfaRFURFb/9EgJsGjHRHLDMe18qg52w0v2ySQUa3fs39RVN6\r\nx2V5jSeNpYKULNQ01A1lflM4u9u73m1hxVEeqqKlIeTvI8iWXBcpudiOtBCG\r\nc2xkJJ2TCMzt+8dRM006jiovRHWs0vhZmkELP5rH5IDL2VlkAEMSDFCtzn4G\r\ns0ypsRq5fViezYwRJZJ7RJ1fjH3wb+0lyH/XCeR5WRQXmI972UdjzBZUQkoX\r\nHSrd1hXVGkH/4LBaW+heVaU3HokaJJwFVqJLyDiKW2T3HFZAJuF0pa+9uKQj\r\nVpw94jq5ieFELIi4wXVAFTA2TMeWCPLy/Ow3ZVtwvKOYKhTLDGXJKTeWa2kb\r\nlN9LwgiiU43jryoflFRoyYzkZDfQxs+WfEyo4twXKNMuAfwLPVVsleXFjY8N\r\n4Q99ER/+AEAP2SBsp9v9NTl1fJxvbstoOBELpvbWno4MFIBn0+/caj1a1jdP\r\n5i9pOLhbJc/Co8DLEJ0fhmq6kojrMYFeYgI=\r\n=f+BV\r\n-----END PGP SIGNATURE-----\r\n","size":6621,"noattachment":false,"key":"/tiny-lru/-/tiny-lru-10.0.0.tgz"},"_npmUser":{"name":"avoidwork","email":"jason.mulligan@avoidwork.com"},"directories":{},"maintainers":[{"name":"avoidwork","email":"jason.mulligan@avoidwork.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tiny-lru_10.0.0_1666921816415_0.3395488658081953"},"_hasShrinkwrap":false,"readme":"# Tiny LRU\r\n\r\nLeast Recently Used cache for Client or Server.\r\n\r\n## Using the factory\r\n\r\n```javascript\r\nimport {lru} from \"tiny-lru\";\r\nconst cache = lru(max, ttl = 0, resetTtl = false);\r\n```\r\n\r\n## Using the Class\r\n\r\n```javascript\r\nimport {LRU} from \"tiny-lru\";\r\nconst cache = new LRU(max, ttl = 0, resetTtl = false);\r\n```\r\n\r\n```javascript\r\nimport {LRU} from \"tiny-lru\";\r\nclass MyCache extends LRU {}\r\n```\r\n\r\n## Interoperability\r\n\r\nLodash provides a `memoize` function with a cache that can be swapped out as long as it implements the right interface.\r\nSee the [lodash docs](https://lodash.com/docs#memoize) for more on `memoize`.\r\n\r\n### Example\r\n```javascript\r\n_.memoize.Cache = lru().constructor;\r\nconst memoized = _.memoize(myFunc);\r\nmemoized.cache.max = 10;\r\n```\r\n\r\n## Testing\r\n\r\nTiny-LRU has 100% code coverage with its tests.\r\n\r\n```console\r\n--------------|---------|----------|---------|---------|-------------------\r\nFile          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\r\n--------------|---------|----------|---------|---------|-------------------\r\nAll files     |     100 |    89.85 |     100 |     100 |                  \r\n tiny-lru.cjs |     100 |    89.85 |     100 |     100 | 11-31,130-138,172\r\n--------------|---------|----------|---------|---------|-------------------\r\n```\r\n\r\n## API\r\n\r\n## Properties\r\n\r\n### first\r\n\r\nItem in \"first\" or \"bottom\" position; default is `null`\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst cache = lru();\r\n\r\ncache.first; // null - it's a new cache!\r\n```\r\n\r\n### last\r\n\r\nItem in \"last\" or \"top\" position; default is `null`\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst cache = lru();\r\n\r\ncache.last; // null - it's a new cache!\r\n```\r\n\r\n### max\r\n\r\nMax items to hold in cache; default is `1000`\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst cache = lru(500);\r\n\r\ncache.max; // 500\r\n```\r\n\r\n### resetTtl\r\n\r\nResets `item.expiry` with each `set()` if `true`; default is `false`\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst cache = lru(500, 5*6e4, true);\r\n\r\ncache.resetTtl; // true\r\n```\r\n\r\n### size\r\n\r\nNumber of items in cache\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst cache = lru();\r\n\r\ncache.size; // 0 - it's a new cache!\r\n```\r\n\r\n### ttl\r\n\r\nMilliseconds an item will remain in cache; lazy expiration upon next `get()` of an item\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst cache = lru(100, 3e4);\r\n\r\ncache.ttl; // 30000;\r\n```\r\n\r\n## Methods\r\n\r\n### clear\r\n\r\nClears the contents of the cache\r\n\r\n\treturn {Object} LRU instance\r\n\r\n**Example**\r\n\r\n```javascript\r\ncache.clear();\r\n```\r\n\r\n### delete\r\n\r\nRemoves item from cache\r\n\r\n\tparam  {String} key Item key\r\n\treturn {Object}     LRU instance\r\n\r\n**Example**\r\n\r\n```javascript\r\ncache.delete(\"myKey\");\r\n```\r\n\r\n### entries(*[\"key1\", \"key2\"]*)\r\n\r\nReturns an `Array` cache items\r\n\r\n    param  {Array} keys (Optional) Cache item keys to get, defaults to `this.keys()` if not provided\r\n\treturn {Object} LRU instance\r\n\r\n**Example**\r\n\r\n```javascript\r\ncache.entries(['myKey1', 'myKey2']);\r\n```\r\n\r\n### evict\r\n\r\nEvicts the least recently used item from cache\r\n\r\n\treturn {Object} LRU instance\r\n\r\n**Example**\r\n\r\n```javascript\r\ncache.evict();\r\n```\r\n\r\n### expiresAt\r\n\r\nGets expiration time for cached item\r\n\r\n\tparam  {String} key Item key\r\n\treturn {Mixed}      Undefined or number (epoch time)\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst item = cache.expiresAt(\"myKey\");\r\n```\r\n\r\n### get\r\n\r\nGets cached item and moves it to the front\r\n\r\n\tparam  {String} key Item key\r\n\treturn {Mixed}      Undefined or Item value\r\n\r\n**Example**\r\n\r\n```javascript\r\nconst item = cache.get(\"myKey\");\r\n```\r\n\r\n### has\r\n\r\nReturns a `Boolean` indicating if `key` is in cache\r\n\r\n\treturn {Object} LRU instance\r\n\r\n**Example**\r\n\r\n```javascript\r\ncache.has('myKey');\r\n```\r\n\r\n### keys\r\n\r\nReturns an `Array` of cache item keys (`first` to `last`)\r\n\r\n\treturn {Array} Array of keys\r\n\r\n**Example**\r\n\r\n```javascript\r\nconsole.log(cache.keys());\r\n```\r\n\r\n### set\r\n\r\nSets item in cache as `first`\r\n\r\n\tparam  {String} key   Item key\r\n\tparam  {Mixed}  value Item value\r\n\treturn {Object}       LRU instance\r\n\r\n**Example**\r\n\r\n```javascript\r\ncache.set(\"myKey\", {prop: true});\r\n```\r\n\r\n### values(*[\"key1\", \"key2\"]*)\r\n\r\nReturns an `Array` cache items\r\n\r\n\tparam  {Array} keys (Optional) Cache item keys to get\r\n\treturn {Array} Cache items\r\n\r\n**Example**\r\n\r\n```javascript\r\ncache.values(['abc', 'def']);\r\n```\r\n\r\n## License\r\nCopyright (c) 2024 Jason Mulligan\r\nLicensed under the BSD-3 license.\r\n","publish_time":1666921816565,"_cnpm_publish_time":1666921816565,"dist-tags":{"latest":"13.1.1"}}