{"name":"tiny-lru","description":"Tiny LRU cache for Client or Server","version":"1.5.2","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","main":"lib/tiny-lru.js","engines":{"node":">=0.8.0"},"scripts":{"test":"grunt test"},"dependencies":{},"devDependencies":{"babel-core":"^6.26.0","babel-preset-env":"^1.6.0","grunt":"^1.0.1","grunt-babel":"^7.0.0","grunt-cli":"^1.2.0","grunt-contrib-concat":"^1.0.1","grunt-contrib-nodeunit":"^1.0.0","grunt-contrib-uglify":"^0.9.1","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^20.1.0"},"keywords":["LRU","cache","tiny","client","server","least","recently","used"],"gitHead":"fb174d7c6b2f465f89419ee7d56c4fdbfa65ffed","_id":"tiny-lru@1.5.2","_npmVersion":"5.6.0","_nodeVersion":"9.9.0","_npmUser":{"name":"avoidwork","email":"jason.mulligan@avoidwork.com"},"dist":{"integrity":"sha512-yAJ76h2GdHGT+9gthdPs+Q9HbXugvACKcAEnZeypJxuLf6cNFduMTfTnZ1JtgcnS47e8ULmO5BoxA0kUkax8Ug==","shasum":"2cef6eab55ff339aee78919262811a4d46d892d1","tarball":"http://registry-npm.ywwl.com/tiny-lru/download/tiny-lru-1.5.2.tgz","fileCount":6,"unpackedSize":17446,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCJBhY5uJfQzsaK3ZGLlw/0dzYRZRlabpIeBqgXcCc8YwIgFZ+F+YVpSDob3slZlb91TMrzQhTLdETD94gk5oaj4rM="}],"size":4920,"noattachment":false,"key":"/tiny-lru/-/tiny-lru-1.5.2.tgz"},"maintainers":[{"name":"avoidwork","email":"jason@attack.io"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tiny-lru_1.5.2_1522251197183_0.27742984613314303"},"_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":1522251197269,"_cnpm_publish_time":1522251197269,"dist-tags":{"latest":"13.1.1"}}