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:
authorisaacs <i@izs.me>2012-08-02 03:09:28 +0400
committerisaacs <i@izs.me>2012-08-02 03:09:28 +0400
commit23dac350607690901c5647eb951e6b43c8897aa1 (patch)
tree945380e3ca82174cac969cb671065263d4f1fbe6 /node_modules/lru-cache
parent501fef23c38e03ed146b44eab0e71c2722cd1c8f (diff)
lru-cache@1.1.1
Diffstat (limited to 'node_modules/lru-cache')
-rw-r--r--node_modules/lru-cache/AUTHORS2
-rw-r--r--node_modules/lru-cache/README.md9
-rw-r--r--node_modules/lru-cache/lib/lru-cache.js15
-rw-r--r--node_modules/lru-cache/package.json28
-rw-r--r--node_modules/lru-cache/test/basic.js39
5 files changed, 72 insertions, 21 deletions
diff --git a/node_modules/lru-cache/AUTHORS b/node_modules/lru-cache/AUTHORS
index d8e20616e..82f1a6675 100644
--- a/node_modules/lru-cache/AUTHORS
+++ b/node_modules/lru-cache/AUTHORS
@@ -3,3 +3,5 @@ Isaac Z. Schlueter <i@izs.me>
Carlos Brito Lage <carlos@carloslage.net>
Marko Mikulicic <marko.mikulicic@isti.cnr.it>
Trent Mick <trentm@gmail.com>
+Kevin O'Hara <kevinohara80@gmail.com>
+Marco Rogers <marco.rogers@gmail.com>
diff --git a/node_modules/lru-cache/README.md b/node_modules/lru-cache/README.md
index f342b519b..7033fea89 100644
--- a/node_modules/lru-cache/README.md
+++ b/node_modules/lru-cache/README.md
@@ -6,12 +6,19 @@ Usage:
var LRU = require("lru-cache")
, cache = LRU(10, // max length. default = Infinity
+
// calculate how "big" each item is
//
// defaults to function(){return 1}, ie, just limit
// the item count, without any knowledge as to their
// relative size.
- function (item) { return item.length })
+ function (item) { return item.length },
+
+ // maxAge in ms
+ // defaults to infinite
+ // items are not pre-emptively pruned, but they
+ // are deleted when fetched if they're too old.
+ 1000 * 60)
cache.set("key", "value")
cache.get("key") // "value"
diff --git a/node_modules/lru-cache/lib/lru-cache.js b/node_modules/lru-cache/lib/lru-cache.js
index 1bd4e5864..407ee6857 100644
--- a/node_modules/lru-cache/lib/lru-cache.js
+++ b/node_modules/lru-cache/lib/lru-cache.js
@@ -4,7 +4,7 @@ if (module) {
module.exports = LRUCache
} else {
// just set the global for non-node platforms.
- ;(function () { return this })().LRUCache = LRUCache
+ this.LRUCache = LRUCache
}
function hOP (obj, key) {
@@ -13,7 +13,7 @@ function hOP (obj, key) {
function naiveLength () { return 1 }
-function LRUCache (maxLength, lengthCalculator) {
+function LRUCache (maxLength, lengthCalculator, maxAge) {
if (!(this instanceof LRUCache)) {
return new LRUCache(maxLength, lengthCalculator)
}
@@ -101,24 +101,30 @@ function LRUCache (maxLength, lengthCalculator) {
if (hOP(cache, key)) {
this.get(key)
cache[key].value = value
- return
+ return true
}
var hit = {key:key, value:value, lu:mru++, length:lengthCalculator(value)}
+ if (maxAge) hit.now = Date.now()
// oversized objects fall out of cache automatically.
- if (hit.length > maxLength) return
+ if (hit.length > maxLength) return false
length += hit.length
lruList[hit.lu] = cache[key] = hit
itemCount ++
if (length > maxLength) trim()
+ return true
}
this.get = function (key) {
if (!hOP(cache, key)) return
var hit = cache[key]
+ if (maxAge && Date.now() - hit.now > maxAge) {
+ this.del(key)
+ return
+ }
delete lruList[hit.lu]
if (hit.lu === lru) lruWalk()
hit.lu = mru ++
@@ -149,6 +155,7 @@ function LRUCache (maxLength, lengthCalculator) {
delete cache[ lruList[prune[i]].key ]
delete lruList[prune[i]]
}
+
lruWalk()
}
}
diff --git a/node_modules/lru-cache/package.json b/node_modules/lru-cache/package.json
index 7240c927f..73c011b72 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": "1.1.0",
+ "version": "1.1.1",
"author": {
"name": "Isaac Z. Schlueter",
"email": "i@izs.me"
@@ -21,11 +21,6 @@
"type": "MIT",
"url": "http://github.com/isaacs/node-lru-cache/raw/master/LICENSE"
},
- "_npmUser": {
- "name": "isaacs",
- "email": "i@izs.me"
- },
- "_id": "lru-cache@1.1.0",
"contributors": [
{
"name": "Isaac Z. Schlueter",
@@ -42,16 +37,17 @@
{
"name": "Trent Mick",
"email": "trentm@gmail.com"
+ },
+ {
+ "name": "Kevin O'Hara",
+ "email": "kevinohara80@gmail.com"
+ },
+ {
+ "name": "Marco Rogers",
+ "email": "marco.rogers@gmail.com"
}
],
- "dependencies": {},
- "optionalDependencies": {},
- "engines": {
- "node": "*"
- },
- "_engineSupported": true,
- "_npmVersion": "1.1.25",
- "_nodeVersion": "v0.7.10-pre",
- "_defaultsLoaded": true,
- "_from": "lru-cache@1"
+ "readme": "# lru cache\n\nA cache object that deletes the least-recently-used items.\n\nUsage:\n\n var LRU = require(\"lru-cache\")\n , cache = LRU(10, // max length. default = Infinity\n\n // calculate how \"big\" each item is\n //\n // defaults to function(){return 1}, ie, just limit\n // the item count, without any knowledge as to their\n // relative size.\n function (item) { return item.length },\n\n // maxAge in ms\n // defaults to infinite\n // items are not pre-emptively pruned, but they\n // are deleted when fetched if they're too old.\n 1000 * 60)\n\n cache.set(\"key\", \"value\")\n cache.get(\"key\") // \"value\"\n\n cache.reset() // empty the cache\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\nRTFS for more info.\n",
+ "_id": "lru-cache@1.1.1",
+ "_from": "lru-cache@~1.1.0"
}
diff --git a/node_modules/lru-cache/test/basic.js b/node_modules/lru-cache/test/basic.js
index 6af0edf6c..c5b25de8b 100644
--- a/node_modules/lru-cache/test/basic.js
+++ b/node_modules/lru-cache/test/basic.js
@@ -169,3 +169,42 @@ test("lru recently gotten with weighed length", function (t) {
t.equal(cache.get("a"), "A")
t.end()
})
+
+test("set returns proper booleans", function(t) {
+ var cache = new LRU(5, function (item) { return item.length })
+ t.equal(cache.set("a", "A"), true)
+
+ // should return false for maxLength exceeded
+ t.equal(cache.set("b", "donuts"), false)
+
+ t.equal(cache.set("b", "B"), true)
+ t.equal(cache.set("c", "CCCC"), true)
+ t.end()
+})
+
+test("drop the old items", function(t) {
+ var cache = new LRU(5, null, 50)
+
+ cache.set("a", "A")
+
+ setTimeout(function () {
+ cache.set("b", "b")
+ t.equal(cache.get("a"), "A")
+ }, 25)
+
+ setTimeout(function () {
+ cache.set("c", "C")
+ // timed out
+ t.notOk(cache.get("a"))
+ }, 51)
+
+ setTimeout(function () {
+ t.notOk(cache.get("b"))
+ t.equal(cache.get("c"), "C")
+ }, 90)
+
+ setTimeout(function () {
+ t.notOk(cache.get("c"))
+ t.end()
+ }, 155)
+})