{"name":"tiny-lru","description":"Tiny LRU cache for Client or Server","version":"1.3.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","main":"lib/tiny-lru","engines":{"node":">=0.8.0"},"scripts":{"test":"grunt test"},"dependencies":{},"devDependencies":{"babel-preset-es2015":"^6.1.2","grunt":"^0.4.5","grunt-babel":"^6.0.0","grunt-cli":"^0.1.13","grunt-contrib-concat":"^0.1.3","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-uglify":"^0.9.1","grunt-contrib-watch":"^0.2.0","grunt-eslint":"~19.0.0","grunt-sed":"^0.1.1"},"keywords":["LRU","cache","tiny","client","server","least","recently","used"],"gitHead":"4c07f2f3fbddc5aa46ff9183ab3cf35de9d9f149","_id":"tiny-lru@1.3.0","_shasum":"2c22fb448b13552f77061939a7031ba343349198","_from":"tiny-lru","_resolved":"file:tiny-lru","_npmVersion":"3.10.9","_nodeVersion":"7.1.0","_npmUser":{"name":"avoidwork","email":"jason.mulligan@avoidwork.com"},"maintainers":[{"name":"avoidwork","email":"jason@attack.io"}],"dist":{"shasum":"2c22fb448b13552f77061939a7031ba343349198","tarball":"http://registry-npm.ywwl.com/tiny-lru/download/tiny-lru-1.3.0.tgz","integrity":"sha512-avGYMgWfDgG4UJcjsJ6K5RQdr655QllgGToABQL1VAAj8J1MSYic2+NIH9/Yh6GIA4na90Owzqnd2Ubt+yJkew==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDtrHV7ajhzUdpNZxthAzbjM4qY287XgORCgi81Y0IMpAIhAJBixf5hbOJ2d7MDL9ggbujEwmPMgLJNKqg/XrkH5HvB"}],"size":4162,"noattachment":false,"key":"/tiny-lru/-/tiny-lru-1.3.0.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/tiny-lru-1.3.0.tgz_1479588070253_0.43786265701055527"},"directories":{},"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":1479588072516,"_cnpm_publish_time":1479588072516,"dist-tags":{"latest":"13.1.1"}}