popular-cache
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -45,5 +45,9 @@ var Item = require('./item'), | ||
var item = this._cache[key]; | ||
// visiting out-dated item is not a hit | ||
// out-dated item is kept for future cache update. | ||
if(this.maxAgeEnabled() && item.age() > this._maxAge) return null; | ||
this._hits++; | ||
var item = track(this, this._cache[key], true); | ||
if(this.maxAgeEnabled() && item.age() > this._maxAge) return null; | ||
item = track(this, item, true); | ||
return item.value(); | ||
@@ -50,0 +54,0 @@ } |
{ | ||
"name": "popular-cache", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "An in-memory LRU cache with built-in statistics and proxy mode.", | ||
@@ -5,0 +5,0 @@ "keywords": "lru, ttl, cache, memory, storage, statistics, analysis, proxy", |
@@ -83,3 +83,3 @@ var assert = require('assert'), | ||
it('should support maxAge option', function(done){ | ||
var cache = pcache({maxAge: 50}); | ||
var cache = pcache({maxAge: 10}); | ||
cache.set('1', 1); | ||
@@ -101,6 +101,6 @@ cache.set('2', 2); | ||
done(); | ||
}, 100); | ||
}, 20); | ||
}) | ||
it('should clean out-dated cache first when reaching size limit and maxAge is set', function(done){ | ||
var cache = pcache({maxSize: 3, maxAge: 50}); | ||
var cache = pcache({maxSize: 3, maxAge: 10}); | ||
cache.set('1', 1); | ||
@@ -117,4 +117,4 @@ cache.set('2', 2); | ||
done(); | ||
}, 100); | ||
}, 20); | ||
}) | ||
}) |
@@ -78,3 +78,3 @@ var assert = require('assert'), | ||
callback(++proxyCalls); | ||
}, 50); | ||
}, 10); | ||
}); | ||
@@ -102,7 +102,7 @@ cache.get('key', function(value){ | ||
var proxyCalls = 0; | ||
var cache = pcache({maxAge: 100}).proxy(function(key, callback){ | ||
var cache = pcache({maxAge: 20}).proxy(function(key, callback){ | ||
// time consuming process | ||
setTimeout(function(){ | ||
callback(++proxyCalls); | ||
}, 50); | ||
}, 10); | ||
}); | ||
@@ -114,2 +114,3 @@ cache.set('key', 'value') | ||
setTimeout(function(){ | ||
// the key should have expired | ||
cache.get('key', function(value){ | ||
@@ -119,4 +120,4 @@ assert.equal(1, value); | ||
}); | ||
},150); | ||
},50); | ||
}) | ||
}) |
@@ -73,2 +73,21 @@ var assert = require('assert'), | ||
}) | ||
it('should not count out-dated visits as a hit', function(done){ | ||
var cache = pcache({maxSize: 10, maxAge: 10}); | ||
cache.set('1', 1); | ||
cache.get('1'); | ||
assert.equal(1, cache.hits()); | ||
setTimeout(function(){ | ||
// this is not a hit | ||
cache.get('1'); | ||
cache.get('1'); | ||
assert.equal(1, cache.size()); | ||
assert.equal(1, cache.hits()); | ||
// out-dated item is not removed on get | ||
cache.set('1', 2); | ||
cache.get('1'); | ||
assert.equal(1, cache.size()); | ||
assert.equal(2, cache.hits()); | ||
done(); | ||
}, 20); | ||
}) | ||
}) |
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
19110
520