appolo-cache
Advanced tools
Comparing version 6.0.3 to 6.0.4
@@ -60,3 +60,3 @@ "use strict"; | ||
this._cache.forEach((item, key) => { | ||
item = this.getItem(key); | ||
item = this.peekItem(key); | ||
if (item) { | ||
@@ -69,5 +69,8 @@ fn.call($this || null, item.value, item.key); | ||
let output = []; | ||
this.forEach((value, key) => { | ||
output.push(key); | ||
}); | ||
let keys = this._cache.keys(); | ||
for (let key of keys) { | ||
if (this.peek(key)) { | ||
output.push(key); | ||
} | ||
} | ||
return output; | ||
@@ -77,11 +80,15 @@ } | ||
let output = []; | ||
this.forEach((value, key) => { | ||
output.push(value); | ||
}); | ||
let keys = this._cache.keys(); | ||
for (let key of keys) { | ||
let value = this.peek(key); | ||
if (value) { | ||
output.push(value); | ||
} | ||
} | ||
return output; | ||
} | ||
prune() { | ||
let keys = this.keys(); | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
this._isValidExpire(this._cache[keys[i]]); | ||
let keys = this._cache.keys(); | ||
for (let key of keys) { | ||
this._isValidExpire(this._cache.get(key)); | ||
} | ||
@@ -174,5 +181,2 @@ } | ||
} | ||
// if (item.maxAge > 0) { | ||
// item.modified = Date.now(); | ||
// } | ||
} | ||
@@ -208,4 +212,13 @@ _link(item) { | ||
} | ||
clear(n) { | ||
this.prune(); | ||
for (let i = 0, len = n; i < len; i++) { | ||
this.del(this._tail.key); | ||
} | ||
} | ||
clearHalf() { | ||
this.clear(Math.floor(this._size / 2)); | ||
} | ||
} | ||
exports.Cache = Cache; | ||
//# sourceMappingURL=cache.js.map |
@@ -90,3 +90,3 @@ import {ListItem} from "./listItem"; | ||
this._cache.forEach((item, key) => { | ||
item = this.getItem(key); | ||
item = this.peekItem(key); | ||
if (item) { | ||
@@ -98,9 +98,13 @@ fn.call($this || null, item.value, item.key) | ||
public keys() { | ||
public keys(): K[] { | ||
let output = []; | ||
this.forEach((value: T, key) => { | ||
output.push(key); | ||
}); | ||
let keys = this._cache.keys(); | ||
for (let key of keys) { | ||
if (this.peek(key)) { | ||
output.push(key); | ||
} | ||
} | ||
return output; | ||
@@ -112,6 +116,13 @@ } | ||
this.forEach((value: T, key) => { | ||
output.push(value); | ||
}); | ||
let keys = this._cache.keys(); | ||
for (let key of keys) { | ||
let value = this.peek(key); | ||
if (value) { | ||
output.push(value); | ||
} | ||
} | ||
return output; | ||
@@ -121,5 +132,7 @@ } | ||
public prune() { | ||
let keys = this.keys(); | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
this._isValidExpire(this._cache[keys[i]]); | ||
let keys = this._cache.keys(); | ||
for (let key of keys) { | ||
this._isValidExpire(this._cache.get(key)); | ||
} | ||
@@ -183,3 +196,2 @@ } | ||
private _del(item: ListItem<K, T>) { | ||
@@ -246,6 +258,2 @@ this._unlink(item); | ||
} | ||
// if (item.maxAge > 0) { | ||
// item.modified = Date.now(); | ||
// } | ||
} | ||
@@ -294,2 +302,13 @@ | ||
public clear(n: number) { | ||
this.prune(); | ||
for (let i = 0, len = n; i < len; i++) { | ||
this.del(this._tail.key); | ||
} | ||
} | ||
public clearHalf() { | ||
this.clear(Math.floor(this._size / 2)); | ||
} | ||
} |
@@ -21,3 +21,3 @@ { | ||
"main": "./index.js", | ||
"version": "6.0.3", | ||
"version": "6.0.4", | ||
"license": "MIT", | ||
@@ -24,0 +24,0 @@ "repository": { |
# Appolo lru cache | ||
[](https://travis-ci.org/shmoop207/appolo-cache) [](https://david-dm.org/shmoop207/appolo-cache) [](https://badge.fury.io/js/appolo-cache) [](https://www.npmjs.com/package/appolo-cache) | ||
[](https://snyk.io/test/github/shmoop207/appolo-cache) | ||
Fast and simple lru cache for node.js written in typescript. | ||
@@ -3,0 +6,0 @@ |
Sorry, the diff of this file is not supported yet
31697
667
82