lru-cache
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -26,6 +26,7 @@ ;(function () { // closure for web browsers | ||
} | ||
max = options.max | ||
if (!options) options = {} | ||
max = options.max | ||
var lengthCalculator = options.length || naiveLength | ||
@@ -36,2 +37,3 @@ | ||
} | ||
if (!max || !(typeof max === "number") || max <= 0 ) { | ||
@@ -103,2 +105,30 @@ // a little bit silly. maybe this should throw? | ||
this.forEach = function (fn, thisp) { | ||
thisp = thisp || this | ||
for (var k = mru - 1; k >= 0; k--) if (lruList[k]) { | ||
var hit = lruList[k] | ||
fn.call(thisp, hit.value, hit.key, this) | ||
} | ||
} | ||
this.keys = function () { | ||
var keys = new Array(itemCount) | ||
var i = 0 | ||
for (var k = mru - 1; k >= 0; k--) if (lruList[k]) { | ||
var hit = lruList[k] | ||
keys[i++] = hit.key | ||
} | ||
return keys | ||
} | ||
this.values = function () { | ||
var values = new Array(itemCount) | ||
var i = 0 | ||
for (var k = mru - 1; k >= 0; k--) if (lruList[k]) { | ||
var hit = lruList[k] | ||
values[i++] = hit.value | ||
} | ||
return values | ||
} | ||
this.reset = function () { | ||
@@ -123,2 +153,6 @@ if (dispose) { | ||
this.dumpLru = function () { | ||
return lruList | ||
} | ||
this.set = function (key, value) { | ||
@@ -125,0 +159,0 @@ if (hOP(cache, key)) { |
{ | ||
"name": "lru-cache", | ||
"description": "A cache object that deletes the least-recently-used items.", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"author": "Isaac Z. Schlueter <i@izs.me>", | ||
"scripts": { | ||
"test": "tap test" | ||
"test": "tap test --gc" | ||
}, | ||
@@ -9,0 +9,0 @@ "main": "lib/lru-cache.js", |
@@ -47,1 +47,42 @@ # lru cache | ||
`nextTick` or `setTimeout` callback or it won't do anything. | ||
* `stale` By default, if you set a `maxAge`, it'll only actually pull | ||
stale items out of the cache when you `get(key)`. (That is, it's | ||
not pre-emptively doing a `setTimeout` or anything.) If you set | ||
`stale:true`, it'll return the stale value before deleting it. If | ||
you don't set this, then it'll return `undefined` when you try to | ||
get a stale entry, as if it had already been deleted. | ||
## API | ||
* `set(key, value)` | ||
* `get(key) => value` | ||
Both of these will update the "recently used"-ness of the key. | ||
They do what you think. | ||
* `del(key)` | ||
Deletes a key out of the cache. | ||
* `reset()` | ||
Clear the cache entirely, throwing away all values. | ||
* `has(key)` | ||
Check if a key is in the cache, without updating the recent-ness | ||
or deleting it for being stale. | ||
* `forEach(function(value,key,cache), [thisp])` | ||
Just like `Array.prototype.forEach`. Iterates over all the keys | ||
in the cache, in order of recent-ness. (Ie, more recently used | ||
items are iterated over first.) | ||
* `keys()` | ||
Return an array of the keys in the cache. | ||
* `values()` | ||
Return an array of the values in the cache. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18688
9
542
88