xache
Advanced tools
Comparing version 1.1.0 to 1.2.0
module.exports = class MaxCache { | ||
constructor ({ maxSize, maxAge, createMap }) { | ||
constructor ({ maxSize, maxAge, createMap, ongc }) { | ||
this.maxSize = maxSize | ||
this.maxAge = maxAge | ||
this.ongc = ongc || null | ||
@@ -99,2 +100,3 @@ this._createMap = createMap || defaultCreateMap | ||
this._gced = true | ||
if (this.ongc !== null && this._oldest.size > 0) this.ongc(this._oldest) | ||
this._oldest = this._latest | ||
@@ -101,0 +103,0 @@ this._latest = this._createMap() |
{ | ||
"name": "xache", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Yet another auto expiring, max sizable cache", | ||
"main": "index.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"brittle": "^2.3.1", | ||
"standard": "^16.0.3" | ||
"brittle": "^3.3.2", | ||
"standard": "^17.1.0" | ||
}, | ||
@@ -11,0 +10,0 @@ "scripts": { |
20
test.js
@@ -89,1 +89,21 @@ const test = require('brittle') | ||
}) | ||
test('ongc', function (t) { | ||
t.plan(1) | ||
const c = new Xache({ | ||
maxSize: 4, | ||
ongc (map) { | ||
t.alike(map, new Map([[1, true], [2, true], [3, true], [4, true]])) | ||
} | ||
}) | ||
c.set(1, true) | ||
c.set(2, true) | ||
c.set(3, true) | ||
c.set(4, true) | ||
c.set(5, true) | ||
c.set(6, true) | ||
c.set(7, true) | ||
c.set(8, true) | ||
}) |
6939
171