lru-cache
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -58,3 +58,3 @@ module.exports = LRUCache | ||
this._cache.forEach(function (value, key) { | ||
value.length = this._lengthCalculator(value.value) | ||
value.length = this._lengthCalculator(value.value, key) | ||
this._length += value.length | ||
@@ -162,3 +162,3 @@ }) | ||
var now = maxAge ? Date.now() : 0 | ||
var len = this._lengthCalculator(value) | ||
var len = this._lengthCalculator(value, key) | ||
@@ -165,0 +165,0 @@ if (this._cache.has(key)) { |
{ | ||
"name": "lru-cache", | ||
"description": "A cache object that deletes the least-recently-used items.", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"author": "Isaac Z. Schlueter <i@izs.me>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -10,3 +10,3 @@ # lru cache | ||
, options = { max: 500 | ||
, length: function (n) { return n * 2 } | ||
, length: function (n, key) { return n * 2 + key.length } | ||
, dispose: function (key, n) { n.close() } | ||
@@ -45,5 +45,6 @@ , maxAge: 1000 * 60 * 60 } | ||
items. If you're storing strings or buffers, then you probably want | ||
to do something like `function(n){return n.length}`. The default is | ||
`function(n){return 1}`, which is fine if you want to store `max` | ||
like-sized things. | ||
to do something like `function(n, key){return n.length}`. The default is | ||
`function(){return 1}`, which is fine if you want to store `max` | ||
like-sized things. They item is passed as the first argument, and | ||
the key is passed as the second argumnet. | ||
* `dispose` Function that is called on items when they are dropped | ||
@@ -50,0 +51,0 @@ from the cache. This can be handy if you want to close file |
@@ -99,3 +99,6 @@ var test = require("tap").test | ||
max: 100, | ||
length: function (item) { return item.size } | ||
length: function (item, key) { | ||
t.isa(key, 'string') | ||
return item.size | ||
} | ||
}) | ||
@@ -105,3 +108,3 @@ cache.set("key", {val: "value", size: 50}) | ||
t.equal(cache.get("nada"), undefined) | ||
t.equal(cache.lengthCalculator(cache.get("key")), 50) | ||
t.equal(cache.lengthCalculator(cache.get("key"), 'key'), 50) | ||
t.equal(cache.length, 50) | ||
@@ -108,0 +111,0 @@ t.equal(cache.max, 100) |
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
30527
947
127