diff options
author | isaacs <i@izs.me> | 2013-09-07 23:24:04 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-09-07 23:24:04 +0400 |
commit | 2a07dd3d87c5d80bee5d30814e2d426c90dd646b (patch) | |
tree | ea4d4403e993d6a5aa666ec40e2b5ea8153a18c5 /node_modules/lru-cache | |
parent | 287eab473073c594aec3c58a28cf40903d80e559 (diff) |
lru-cache@2.3.1
Diffstat (limited to 'node_modules/lru-cache')
-rw-r--r-- | node_modules/lru-cache/bench.js (renamed from node_modules/lru-cache/s.js) | 2 | ||||
-rw-r--r-- | node_modules/lru-cache/lib/lru-cache.js | 8 | ||||
-rw-r--r-- | node_modules/lru-cache/package.json | 13 |
3 files changed, 18 insertions, 5 deletions
diff --git a/node_modules/lru-cache/s.js b/node_modules/lru-cache/bench.js index c2a9e548f..91115400b 100644 --- a/node_modules/lru-cache/s.js +++ b/node_modules/lru-cache/bench.js @@ -1,7 +1,7 @@ var LRU = require('lru-cache'); var max = +process.argv[2] || 10240; -var more = 1024; +var more = 102400; var cache = LRU({ max: max, maxAge: 86400e3 diff --git a/node_modules/lru-cache/lib/lru-cache.js b/node_modules/lru-cache/lib/lru-cache.js index 8c80853fd..49c1dc6de 100644 --- a/node_modules/lru-cache/lib/lru-cache.js +++ b/node_modules/lru-cache/lib/lru-cache.js @@ -107,7 +107,13 @@ function LRUCache (options) { for (var k = mru - 1; k >= 0 && i < itemCount; k--) if (lruList[k]) { i++ var hit = lruList[k] - fn.call(thisp, hit.value, hit.key, this) + if (maxAge && (Date.now() - hit.now > maxAge)) { + del(hit) + if (!allowStale) hit = undefined + } + if (hit) { + fn.call(thisp, hit.value, hit.key, this) + } } } diff --git a/node_modules/lru-cache/package.json b/node_modules/lru-cache/package.json index d5a4e8c6d..e8df4d32b 100644 --- a/node_modules/lru-cache/package.json +++ b/node_modules/lru-cache/package.json @@ -1,7 +1,7 @@ { "name": "lru-cache", "description": "A cache object that deletes the least-recently-used items.", - "version": "2.3.0", + "version": "2.3.1", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me" @@ -54,6 +54,13 @@ ], "readme": "# lru cache\n\nA cache object that deletes the least-recently-used items.\n\n## Usage:\n\n```javascript\nvar LRU = require(\"lru-cache\")\n , options = { max: 500\n , length: function (n) { return n * 2 }\n , dispose: function (key, n) { n.close() }\n , maxAge: 1000 * 60 * 60 }\n , cache = LRU(options)\n , otherCache = LRU(50) // sets just the max size\n\ncache.set(\"key\", \"value\")\ncache.get(\"key\") // \"value\"\n\ncache.reset() // empty the cache\n```\n\nIf you put more stuff in it, then items will fall out.\n\nIf you try to put an oversized thing in it, then it'll fall out right\naway.\n\n## Options\n\n* `max` The maximum size of the cache, checked by applying the length\n function to all values in the cache. Not setting this is kind of\n silly, since that's the whole purpose of this lib, but it defaults\n to `Infinity`.\n* `maxAge` Maximum age in ms. Items are not pro-actively pruned out\n as they age, but if you try to get an item that is too old, it'll\n drop it and return undefined instead of giving it to you.\n* `length` Function that is used to calculate the length of stored\n items. If you're storing strings or buffers, then you probably want\n to do something like `function(n){return n.length}`. The default is\n `function(n){return 1}`, which is fine if you want to store `n`\n like-sized things.\n* `dispose` Function that is called on items when they are dropped\n from the cache. This can be handy if you want to close file\n descriptors or do other cleanup tasks when items are no longer\n accessible. Called with `key, value`. It's called *before*\n actually removing the item from the internal cache, so if you want\n to immediately put it back in, you'll have to do that in a\n `nextTick` or `setTimeout` callback or it won't do anything.\n* `stale` By default, if you set a `maxAge`, it'll only actually pull\n stale items out of the cache when you `get(key)`. (That is, it's\n not pre-emptively doing a `setTimeout` or anything.) If you set\n `stale:true`, it'll return the stale value before deleting it. If\n you don't set this, then it'll return `undefined` when you try to\n get a stale entry, as if it had already been deleted.\n\n## API\n\n* `set(key, value)`\n* `get(key) => value`\n\n Both of these will update the \"recently used\"-ness of the key.\n They do what you think.\n\n* `peek(key)`\n\n Returns the key value (or `undefined` if not found) without\n updating the \"recently used\"-ness of the key.\n\n (If you find yourself using this a lot, you *might* be using the\n wrong sort of data structure, but there are some use cases where\n it's handy.)\n\n* `del(key)`\n\n Deletes a key out of the cache.\n\n* `reset()`\n\n Clear the cache entirely, throwing away all values.\n\n* `has(key)`\n\n Check if a key is in the cache, without updating the recent-ness\n or deleting it for being stale.\n\n* `forEach(function(value,key,cache), [thisp])`\n\n Just like `Array.prototype.forEach`. Iterates over all the keys\n in the cache, in order of recent-ness. (Ie, more recently used\n items are iterated over first.)\n\n* `keys()`\n\n Return an array of the keys in the cache.\n\n* `values()`\n\n Return an array of the values in the cache.\n", "readmeFilename": "README.md", - "_id": "lru-cache@2.3.0", - "_from": "lru-cache@latest" + "bugs": { + "url": "https://github.com/isaacs/node-lru-cache/issues" + }, + "_id": "lru-cache@2.3.1", + "dist": { + "shasum": "b3adf6b3d856e954e2c390e6cef22081245a53d6" + }, + "_from": "lru-cache@2.3.1", + "_resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.3.1.tgz" } |