Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForrest L Norvell <forrest@npmjs.com>2015-04-13 05:04:25 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-04-13 05:04:25 +0300
commit16427c1f3ea3d71ee753c62eb4c2663c7b32b84f (patch)
tree64e75b521131632c51d5f58e9b42290fc7b88393 /node_modules/lru-cache
parented7e249d50444312cd266942ce3b89e1ca049bdf (diff)
lru-cache@2.5.2
More accurate updating of last access time when `maxAge` is set.
Diffstat (limited to 'node_modules/lru-cache')
-rw-r--r--node_modules/lru-cache/lib/lru-cache.js1
-rw-r--r--node_modules/lru-cache/package.json31
-rw-r--r--node_modules/lru-cache/t.js25
-rw-r--r--node_modules/lru-cache/test/basic.js2
-rw-r--r--node_modules/lru-cache/test/timeout.js21
5 files changed, 73 insertions, 7 deletions
diff --git a/node_modules/lru-cache/lib/lru-cache.js b/node_modules/lru-cache/lib/lru-cache.js
index d1d138172..7d3b04f9d 100644
--- a/node_modules/lru-cache/lib/lru-cache.js
+++ b/node_modules/lru-cache/lib/lru-cache.js
@@ -217,6 +217,7 @@ function get (self, key, doUse) {
function use (self, hit) {
shiftLU(self, hit)
hit.lu = self._mru ++
+ if (self._maxAge) hit.now = Date.now()
self._lruList[hit.lu] = hit
}
diff --git a/node_modules/lru-cache/package.json b/node_modules/lru-cache/package.json
index d3fbddbdf..9e2d81f48 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.5.0",
+ "version": "2.5.2",
"author": {
"name": "Isaac Z. Schlueter",
"email": "i@izs.me"
@@ -15,19 +15,38 @@
"url": "git://github.com/isaacs/node-lru-cache.git"
},
"devDependencies": {
- "tap": "",
+ "tap": "^0.7.1",
"weak": ""
},
"license": {
"type": "MIT",
"url": "http://github.com/isaacs/node-lru-cache/raw/master/LICENSE"
},
- "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",
+ "gitHead": "ec01cc48ac06ee07b2b56a219d5aa931f899b21b",
"bugs": {
"url": "https://github.com/isaacs/node-lru-cache/issues"
},
"homepage": "https://github.com/isaacs/node-lru-cache",
- "_id": "lru-cache@2.5.0",
- "_from": "lru-cache@latest"
+ "_id": "lru-cache@2.5.2",
+ "_shasum": "1fddad938aae1263ce138680be1b3f591c0ab41c",
+ "_from": "lru-cache@>=2.5.2 <2.6.0",
+ "_npmVersion": "2.7.6",
+ "_nodeVersion": "1.4.2",
+ "_npmUser": {
+ "name": "isaacs",
+ "email": "i@izs.me"
+ },
+ "maintainers": [
+ {
+ "name": "isaacs",
+ "email": "i@izs.me"
+ }
+ ],
+ "dist": {
+ "shasum": "1fddad938aae1263ce138680be1b3f591c0ab41c",
+ "tarball": "http://registry.npmjs.org/lru-cache/-/lru-cache-2.5.2.tgz"
+ },
+ "directories": {},
+ "_resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.2.tgz",
+ "readme": "ERROR: No README data found!"
}
diff --git a/node_modules/lru-cache/t.js b/node_modules/lru-cache/t.js
new file mode 100644
index 000000000..08e51809a
--- /dev/null
+++ b/node_modules/lru-cache/t.js
@@ -0,0 +1,25 @@
+var LRU = require("./");
+
+var cache = LRU( {
+ max: 1,
+ maxAge: 1000
+} );
+
+cache.set( "1234", 1 );
+
+setTimeout( function() {
+ cache.set( "1234", 2 );
+ console.log( "testing after 5s: " + cache.get( "1234" ) );
+}, 500 );
+
+setTimeout( function() {
+ console.log( "testing after 9s: " + cache.get( "1234" ) );
+}, 900 );
+
+setTimeout( function() {
+ console.log( "testing after 11s: " + cache.get( "1234" ) );
+}, 1100 );
+
+setTimeout( function() {
+ console.log( "testing after 16s: " + cache.get( "1234" ) );
+}, 1600 );
diff --git a/node_modules/lru-cache/test/basic.js b/node_modules/lru-cache/test/basic.js
index f72697c46..799e72dfb 100644
--- a/node_modules/lru-cache/test/basic.js
+++ b/node_modules/lru-cache/test/basic.js
@@ -215,7 +215,7 @@ test("drop the old items", function(t) {
cache.set("c", "C")
// timed out
t.notOk(cache.get("a"))
- }, 60)
+ }, 60 + 25)
setTimeout(function () {
t.notOk(cache.get("b"))
diff --git a/node_modules/lru-cache/test/timeout.js b/node_modules/lru-cache/test/timeout.js
new file mode 100644
index 000000000..5dce62a9e
--- /dev/null
+++ b/node_modules/lru-cache/test/timeout.js
@@ -0,0 +1,21 @@
+var test = require("tap").test
+var LRU = require("../")
+
+var cache = LRU( {
+ max: 1,
+ maxAge: 500
+} );
+
+test('set the key', function (t) {
+ cache.set( "1234", 1 );
+ t.end()
+})
+
+for (var i = 0; i < 10; i ++) {
+ test('get after ' + i + '00ms', function (t) {
+ setTimeout(function () {
+ t.equal(cache.get('1234'), 1)
+ t.end()
+ }, 100)
+ })
+}