{"_id":"redis-lru","_rev":"10-527a04de454e17933e93a5e4febeaf6d","name":"redis-lru","description":"redis-backed LRU cache","dist-tags":{"latest":"0.6.0"},"versions":{"0.1.0":{"name":"redis-lru","version":"0.1.0","description":"redis-backed LRU cache","main":"index.js","scripts":{"test":"mocha && eslint ."},"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"keywords":["redis","lru","cache"],"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"homepage":"https://github.com/facundoolano/redis-lru","devDependencies":{"eslint":"^3.8.0","eslint-config-semistandard":"^6.0.1","eslint-config-standard":"^5.1.0","eslint-plugin-promise":"^1.1.0","eslint-plugin-standard":"^1.3.2","mocha":"^2.4.5"},"author":{"name":"Facundo Olano"},"license":"MIT","gitHead":"a2f18943e36db368207a0ac0f416b47ee8dcc562","_id":"redis-lru@0.1.0","_shasum":"ac7e6c566217ec0088b43f3f950659f53dc74c20","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.9.1","_npmUser":{"name":"facundoolano","email":"facundo.olano@gmail.com"},"dist":{"shasum":"ac7e6c566217ec0088b43f3f950659f53dc74c20","tarball":"https://registry.npmjs.org/redis-lru/-/redis-lru-0.1.0.tgz","integrity":"sha512-cD8bqgJ+pKyxk5PWxqgmYKp6jJZjGuBNTEUn8cFOXeQ27WpY2KeMVI3mjb8DCn0SHGUW1NhR3N+5NmpA6g5/8g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCQhZv2/U2q7o1vlvnv3Whwl0GHOQKAiIehHBPSue7bDgIhAPe+MGRALX2F8NIwMjfHGqb/DQSj6Cfe8vXtHIFoOOAe"}]},"maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/redis-lru-0.1.0.tgz_1480817525989_0.7561159820761532"},"directories":{}},"0.2.0":{"name":"redis-lru","version":"0.2.0","description":"redis-backed LRU cache","main":"index.js","scripts":{"test":"mocha && eslint ."},"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"keywords":["redis","lru","cache"],"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"homepage":"https://github.com/facundoolano/redis-lru","devDependencies":{"eslint":"^3.8.0","eslint-config-semistandard":"^6.0.1","eslint-config-standard":"^5.1.0","eslint-plugin-promise":"^1.1.0","eslint-plugin-standard":"^1.3.2","mocha":"^2.4.5"},"author":{"name":"Facundo Olano"},"license":"MIT","gitHead":"f9130e7b9ed22332527e24d0214c1d48fd7aa65a","_id":"redis-lru@0.2.0","_shasum":"c51ed7a161fc2e5ac9b2a7743b5c0553dedcc078","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.9.1","_npmUser":{"name":"facundoolano","email":"facundo.olano@gmail.com"},"dist":{"shasum":"c51ed7a161fc2e5ac9b2a7743b5c0553dedcc078","tarball":"https://registry.npmjs.org/redis-lru/-/redis-lru-0.2.0.tgz","integrity":"sha512-9HBynr40lM/wztnnwxhJuIXJvjO0i/tlJLdsN4d3zTiWPA8UvoLw9/cJc+mdbpdzXU8gVaqGZDUV6scv2IARYA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC1DLqCInRPnJWEPw1VcEqtSRo8wmUaV6OtTD3tWqjnRQIhAKhc6uSHQ7pqKSraCTayzqgcBmKfPJhkKLLI0wMhlno7"}]},"maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/redis-lru-0.2.0.tgz_1481402833809_0.21538893785327673"},"directories":{}},"0.3.0":{"name":"redis-lru","version":"0.3.0","description":"redis-backed LRU cache","main":"index.js","scripts":{"test":"mocha && eslint ."},"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"keywords":["redis","lru","cache"],"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"homepage":"https://github.com/facundoolano/redis-lru","devDependencies":{"eslint":"^3.8.0","eslint-config-semistandard":"^6.0.1","eslint-config-standard":"^5.1.0","eslint-plugin-promise":"^1.1.0","eslint-plugin-standard":"^1.3.2","mocha":"^2.4.5"},"author":{"name":"Facundo Olano"},"license":"MIT","gitHead":"8e6d0726aa11fe7418e180c8acc4aca608518368","_id":"redis-lru@0.3.0","_shasum":"dd6a3d0c383e3f32ea3252da9fbb7a4f65aa39a1","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.9.1","_npmUser":{"name":"facundoolano","email":"facundo.olano@gmail.com"},"dist":{"shasum":"dd6a3d0c383e3f32ea3252da9fbb7a4f65aa39a1","tarball":"https://registry.npmjs.org/redis-lru/-/redis-lru-0.3.0.tgz","integrity":"sha512-FAr8+9vWNLZcZ2B05+Z9cIcAV4LyFOacD3YMFiuIqNDMg2a710WMAW/UWrd1XD3JUjTV4CLhcRIOu3aId/Pqyw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA0wmhUZtkrC/u/4jdXwTI0lhFQkTx2vJOr7rNT22DgAAiBSmUTI4nVFBnTlSc5VMO/4W8L/QSQe1qaKNTwPz1Bm/A=="}]},"maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/redis-lru-0.3.0.tgz_1481415224354_0.497264810372144"},"directories":{}},"0.4.0":{"name":"redis-lru","version":"0.4.0","description":"redis-backed LRU cache","main":"index.js","scripts":{"test":"mocha && eslint ."},"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"keywords":["redis","lru","cache"],"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"homepage":"https://github.com/facundoolano/redis-lru","devDependencies":{"eslint":"^3.8.0","eslint-config-semistandard":"^6.0.1","eslint-config-standard":"^5.1.0","eslint-plugin-promise":"^1.1.0","eslint-plugin-standard":"^1.3.2","mocha":"^2.4.5"},"author":{"name":"Facundo Olano"},"license":"MIT","gitHead":"c9e5c07d0f700398be9100e7f3777396dc953827","_id":"redis-lru@0.4.0","_shasum":"cb2969c0f7a1c86c98f411ec8c2c2286160ed735","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.9.1","_npmUser":{"name":"facundoolano","email":"facundo.olano@gmail.com"},"dist":{"shasum":"cb2969c0f7a1c86c98f411ec8c2c2286160ed735","tarball":"https://registry.npmjs.org/redis-lru/-/redis-lru-0.4.0.tgz","integrity":"sha512-nbdM7JqohXXR+UzMuBX0AK9ReMnDWRWaaLgNr3k9W8rw6qMcD/PHe4z1JhbfRPs/VwmsFKyP3wFbDD0lUaN2RQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCn+oO7wdIJBKVqignD8vd0rucrxhkD8oXIf6psknNHcwIgYvG+q/9efzLdNNRrpJeOV5TqGkxM0JxxNbaiV79rmvQ="}]},"maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/redis-lru-0.4.0.tgz_1481478155593_0.8659055384341627"},"directories":{}},"0.4.1":{"name":"redis-lru","version":"0.4.1","description":"redis-backed LRU cache","main":"index.js","scripts":{"test":"mocha && eslint ."},"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"keywords":["redis","lru","cache"],"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"homepage":"https://github.com/facundoolano/redis-lru","devDependencies":{"eslint":"^3.8.0","eslint-config-semistandard":"^6.0.1","eslint-config-standard":"^5.1.0","eslint-plugin-promise":"^1.1.0","eslint-plugin-standard":"^1.3.2","mocha":"^2.4.5"},"author":{"name":"Facundo Olano"},"license":"MIT","gitHead":"c82aa5993c071c9e8dbe2ff9a718057a28fc2031","_id":"redis-lru@0.4.1","_shasum":"270a14d05167457cf8e1e44da9b141f20f92e350","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.9.1","_npmUser":{"name":"facundoolano","email":"facundo.olano@gmail.com"},"dist":{"shasum":"270a14d05167457cf8e1e44da9b141f20f92e350","tarball":"https://registry.npmjs.org/redis-lru/-/redis-lru-0.4.1.tgz","integrity":"sha512-l0qdtu9bnpKnJGhj7EtZXd1XmGNRWYX4AH0StX4rP2rY+YBjFxF3IGnBiib358UyogbKzDIRc8KYgCO2HUg/Gg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC4PVdVXTlvYOgkeo0xy3eSSk8GkduX0fjc+ley0vTixAiEA56S5BsfGvckSbu2EJLIb7kZdMkK4wJOVCGsU3KfxyeQ="}]},"maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/redis-lru-0.4.1.tgz_1481479138074_0.1337147713638842"},"directories":{}},"0.5.0":{"name":"redis-lru","version":"0.5.0","description":"redis-backed LRU cache","main":"index.js","scripts":{"test":"mocha && eslint ."},"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"keywords":["redis","lru","cache"],"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"homepage":"https://github.com/facundoolano/redis-lru","devDependencies":{"eslint":"^3.8.0","eslint-config-semistandard":"^6.0.1","eslint-config-standard":"^5.1.0","eslint-plugin-promise":"^1.1.0","eslint-plugin-standard":"^1.3.2","mocha":"^2.4.5"},"author":{"name":"Facundo Olano"},"license":"MIT","gitHead":"8dd2c8d0614529be00318fba67d538fc939097cc","_id":"redis-lru@0.5.0","_shasum":"d1984f1879acbba5f49b0304c362b6b20dcb63f8","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.7.3","_npmUser":{"name":"facundoolano","email":"facundo.olano@gmail.com"},"dist":{"shasum":"d1984f1879acbba5f49b0304c362b6b20dcb63f8","tarball":"https://registry.npmjs.org/redis-lru/-/redis-lru-0.5.0.tgz","integrity":"sha512-LaS9E+aH0MnCBL7kXEsKdru4b3hzrctzb2Olg95pyiOt8dROg9xzvqm3Tp0TeMw49cw9kiDkKr/zdkosHJWRZA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHmXd82o+gwjMzRLly3LwkMLpNETanbbZ4+Av5w/86EvAiAhulaM/b6HX2iG3ykKBhxXsgJbvdPpaxJGZXB7yG8pNA=="}]},"maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/redis-lru-0.5.0.tgz_1489252578121_0.05376723129302263"},"directories":{}},"0.6.0":{"name":"redis-lru","version":"0.6.0","description":"redis-backed LRU cache","main":"index.js","scripts":{"test":"mocha && eslint ."},"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"keywords":["redis","lru","cache"],"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"homepage":"https://github.com/facundoolano/redis-lru","devDependencies":{"eslint":"^3.8.0","eslint-config-semistandard":"^6.0.1","eslint-config-standard":"^5.1.0","eslint-plugin-promise":"^1.1.0","eslint-plugin-standard":"^1.3.2","mocha":"^2.4.5"},"author":{"name":"Facundo Olano"},"license":"MIT","gitHead":"4b0e03286bf002d45a3befc0ec6d4cec2f7178b8","_id":"redis-lru@0.6.0","_npmVersion":"5.6.0","_nodeVersion":"9.9.0","_npmUser":{"name":"facundoolano","email":"facundo.olano@gmail.com"},"dist":{"integrity":"sha512-nDH+EHcUXp+cJdnkq8Hb+99kr82EDmAiFY40Bb02nB00A4N/dUqw3SCIJSgH8SUP2uee9EFijbMlf5WSul22uw==","shasum":"2a820a99011fe1a16a7ad2d67980def9d3336c7a","tarball":"https://registry.npmjs.org/redis-lru/-/redis-lru-0.6.0.tgz","fileCount":7,"unpackedSize":32315,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcbW9mCRA9TVsSAnZWagAAJQ8P/An7JTQGYLAxbpV4o5A5\n5uo+9lssoxJsCKvWB08cqJUCx6AT7EwFa4JWFN2YzXoWJ2Xub0iC4HpSpI/t\nx7QYPFCpJKsrFQGp/NxMdQdxKADcie7f744g+EqOpPcrobrf7qh9T0wnN19U\na9WlyQMayoIlEFOtI/ESYcZc5qjCqsJArBH0a07SS5PsH2qJ5J72qJ7qhbt4\ncOIhDEllzyCGxJ+z2X2jLSJD1uzDwhYstePuxf/20eS7Zk8HhN9l0DG/nqfs\ngotCFzuYvdpppwX5o+H3C9ZpJGK2AiUwEJjlDpux5FsS1JFrihIiCGQIJKgP\niR2qmpNKFx7ieWVEDJLu+wazKQPSOMz6Tu+frNVlwRryPWlEUirMDhQHwiW9\np8d3JgMtOnO5qZ10OuO9OVs9oofm4lp2r1OGUuBSOc/zKBnYT/xLKRqnu5e0\nXLgAFzYnRwCYFCjOoHw6jZ0ptk5/T+E70Ggy/K3nFNW2WgL+gpNPeiyt5DMv\n7fQHxO5QxXXv2ek7HlVGYuC6beq59gdJGPZ1pu7kpcCQhuisRvacIhpUr+Rc\nh+/oNIHOvq1Uav2bO4SZHAxBv+RtU8Z5ZhbjNtu2bwJyxgAx8vnLTelLzyKU\nz8kRX0O5C8+gFDpZ7HhF3fSQ4HXZWV4MjnDS30h/P5CBRniqvyhDKJmst64t\n6vCz\r\n=fxnO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFSGdWGqXMthNPy5RwtnLzQood/GpAMbf7PMX5SnCxJhAiAv8v6tbbYS9uoVew3OFeQWWkAdzZ5toUlfj3DtE2Bhzg=="}]},"maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redis-lru_0.6.0_1550675814258_0.4458987731568833"},"_hasShrinkwrap":false}},"readme":"# redis lru cache [![Build Status](https://secure.travis-ci.org/facundoolano/redis-lru.png)](http://travis-ci.org/facundoolano/redis-lru)\n\nA least recently used (LRU) cache backed by Redis, allowing data to be shared by\nmultiple Node.JS processes. API inspired by [node-lru-cache](https://github.com/isaacs/node-lru-cache).\n\n```js\nvar redis = require('redis').createClient(port, host, opts);\nvar lru = require('redis-lru');\n\nvar personCache = lru(redis, 5); // up to 5 items\n\npersonCache.set('john', {name: 'John Doe', age: 27})\n  .then(() => personCache.set('jane', {name: 'Jane Doe', age: 30}))\n  .then(() => personCache.get('john'))\n  .then(console.log) // prints {name: 'John Doe', age: 27}\n  .then(() => personCache.reset()) //clear the cache\n\nvar bandCache = lru(redis, {max: 2, namespace: 'bands', maxAge: 15000}); // use a different namespace and set expiration\n\nbandCache.set('beatles', 'john, paul, george, ringo')\n  .then(() => bandCache.set('zeppelin', 'jimmy, robert, john, bonzo'))\n  .then(() => bandCache.get('beatles')) // now beatles are the most recently accessed\n  .then(console.log) // 'john, paul, george, ringo'\n  .then(() => bandCache.set('floyd', 'david, roger, syd, richard, nick')) // cache full, remove least recently accessed\n  .then(() => bandCache.get('zeppelin'))\n  .then(console.log) // null, was evicted from cache\n```\n\nWorks both with [node_redis](https://github.com/NodeRedis/node_redis) and [ioredis](https://github.com/luin/ioredis) clients.\n\n## Installation\n\n```\nnpm install redis-lru\n```\n\n## Options\n\n* `max`: Maximum amount of items the cache can hold. This option is required; if no\nother option is needed, it can be passed directly as the second parameter when creating\nthe cache.\n* `namespace`: Prefix appended to all keys saved in Redis, to avoid clashes with other applications\nand to allow multiple instances of the cache.\n* `maxAge`: Maximum amount of milliseconds the key will be kept in the cache; after that getting/peeking will\nresolve to `null`. Note that the value will be removed from Redis after `maxAge`, but the key will\nbe kept in the cache until next time it's accessed (i.e. it will be included in `count`, `keys`, etc., although not in `has`.).\n* `score`: function to customize the score used to order the elements in the cache. Defaults to `() => new Date().getTime()`\n* `increment`: if `true`, on each access the result of the `score` function is added to the previous one,\nrather than replacing it.\n\n## API\n\nAll methods return a Promise.\n\n* `set(key, value, maxAge)`: set value for the given key, marking it as the most recently accessed one.\nKeys should be strings, values will be JSON.stringified. The optional `maxAge` overrides for this specific key\nthe global expiration of the cache.\n* `get(key)`: resolve to the value stored in the cache for the given key or `null` if not present.\nIf present, the key will be marked as the most recently accessed one.\n* `getOrSet(key, fn, maxAge)`: resolve to the value stored in the cache for the given key. If not present,\nexecute `fn`, save the result in the cache and return it. `fn` should be a no args function that\nreturns a value or a promise. If `maxAge` is passed, it will be used only if the key is not already in the cache.\n* `peek(key)`: resolve to the value stored in the cache for the given key, without changing its\nlast accessed time.\n* `del(key)`: removes the item from the cache.\n* `reset()`: empties the cache.\n* `has(key)`: resolves to true if the given key is present in the cache.\n* `keys()`: resolves to an array of keys in the cache, sorted from most to least recently accessed.\n* `values()`: resolves to an array of values in the cache, sorted from most to least recently accessed.\n* `count()`: resolves to the number of items currently in the cache.\n\n### Using as a LFU cache\n\nBy using a custom `score` function and the `increment` option, one can turn the cache\ninto a least frequently used (LFU), where the items that have been accessed more times\n(rather than most recently) are preserved:\n\n```js\nvar redis = require('redis').createClient(port, host, opts);\nvar lru = require('redis-lru');\n\nvar bandLfu = lru(redis, {max: 2, score: () => 1, increment: true});\n\nbandLfu.set('beatles', 'john, paul, george, ringo')\n  .then(() => bandLfu.get('beatles')) // accessed twice\n  .then(() => bandLfu.set('zeppelin', 'jimmy, robert, john, bonzo'))\n  .then(() => bandLfu.set('floyd', 'david, roger, syd, richard, nick')) // cache full, remove least frequently accessed\n  .then(() => bandLfu.get('zeppelin'))\n  .then(console.log) // null, was evicted from cache\n```\n\n## Implementation\n\nEach item in the cache is stored as a regular key/value in Redis. Additionally,\na [ZSET](https://redis.io/topics/data-types#sorted-sets) is used to keep an\nindex of the keys sorted by last-accessed timestamp.\n\nRequires Redis 3.0.2 or greater, since it uses the\n[XX option of ZADD](https://redis.io/commands/zadd#zadd-options-redis-302-or-greater).\n","maintainers":[{"name":"facundoolano","email":"facundo.olano@gmail.com"}],"time":{"modified":"2022-06-26T09:46:13.527Z","created":"2016-12-04T02:12:06.345Z","0.1.0":"2016-12-04T02:12:06.345Z","0.2.0":"2016-12-10T20:47:15.772Z","0.3.0":"2016-12-11T00:13:46.362Z","0.4.0":"2016-12-11T17:42:37.569Z","0.4.1":"2016-12-11T17:59:00.023Z","0.5.0":"2017-03-11T17:16:18.386Z","0.6.0":"2019-02-20T15:16:54.390Z"},"homepage":"https://github.com/facundoolano/redis-lru","keywords":["redis","lru","cache"],"repository":{"type":"git","url":"git+https://github.com/facundoolano/redis-lru.git"},"author":{"name":"Facundo Olano"},"bugs":{"url":"https://github.com/facundoolano/redis-lru/issues"},"license":"MIT","readmeFilename":"README.md"}