Comparing version 1.4.0 to 1.4.1
@@ -0,0 +0,0 @@ { |
var path = require("path"); | ||
module.exports = require(path.join(__dirname, "lib", Number(process.version.replace("v", "").split(".")[0]) >= 6 ? "tiny-lru.es6" : "tiny-lru")); |
@@ -8,3 +8,3 @@ /** | ||
* @link https://github.com/avoidwork/tiny-lru | ||
* @version 1.4.0 | ||
* @version 1.4.1 | ||
*/ | ||
@@ -47,4 +47,4 @@ "use strict"; | ||
delete (key) { | ||
return this.remove(key); | ||
delete (key, silent = false) { | ||
return this.remove(key, silent); | ||
} | ||
@@ -69,12 +69,11 @@ | ||
get (key) { | ||
let cached = this.cache[key], | ||
output; | ||
let output; | ||
if (cached) { | ||
output = cached.value; | ||
this.set(key, cached.value); | ||
} | ||
if (this.has(key)) { | ||
output = this.cache[key].value; | ||
this.set(key, output); | ||
if (this.notify) { | ||
next(this.onchange("get", this.dump())); | ||
if (this.notify) { | ||
next(this.onchange("get", this.dump())); | ||
} | ||
} | ||
@@ -86,3 +85,3 @@ | ||
has (key) { | ||
return this.cache[key] !== undefined; | ||
return key in this.cache; | ||
} | ||
@@ -112,6 +111,6 @@ | ||
} | ||
} | ||
if (!silent && this.notify) { | ||
next(this.onchange("remove", this.dump())); | ||
if (!silent && this.notify) { | ||
next(this.onchange("remove", this.dump())); | ||
} | ||
} | ||
@@ -123,18 +122,25 @@ | ||
set (key, value) { | ||
let obj = this.remove(key, true); | ||
let item; | ||
if (!obj) { | ||
obj = { | ||
if (this.has(key)) { | ||
item = this.cache[key]; | ||
item.value = value; | ||
item.next = null; | ||
item.previous = this.first; | ||
} else { | ||
if (++this.length > this.max) { | ||
this.remove(this.last, true); | ||
} | ||
if (this.length === 1) { | ||
this.last = key; | ||
} | ||
this.cache[key] = { | ||
next: null, | ||
previous: null, | ||
previous: this.first, | ||
value: value | ||
}; | ||
} else { | ||
obj.value = value; | ||
} | ||
obj.next = null; | ||
obj.previous = this.first; | ||
this.cache[key] = obj; | ||
if (this.first) { | ||
@@ -146,10 +152,2 @@ this.cache[this.first].next = key; | ||
if (!this.last) { | ||
this.last = key; | ||
} | ||
if (++this.length > this.max) { | ||
this.evict(); | ||
} | ||
if (this.notify) { | ||
@@ -156,0 +154,0 @@ next(this.onchange("set", this.dump())); |
@@ -8,3 +8,3 @@ /** | ||
* @link https://github.com/avoidwork/tiny-lru | ||
* @version 1.4.0 | ||
* @version 1.4.1 | ||
*/ | ||
@@ -63,3 +63,5 @@ "use strict"; | ||
value: function _delete(key) { | ||
return this.remove(key); | ||
var silent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
return this.remove(key, silent); | ||
} | ||
@@ -87,12 +89,11 @@ }, { | ||
value: function get(key) { | ||
var cached = this.cache[key], | ||
output = void 0; | ||
var output = void 0; | ||
if (cached) { | ||
output = cached.value; | ||
this.set(key, cached.value); | ||
} | ||
if (this.has(key)) { | ||
output = this.cache[key].value; | ||
this.set(key, output); | ||
if (this.notify) { | ||
next(this.onchange("get", this.dump())); | ||
if (this.notify) { | ||
next(this.onchange("get", this.dump())); | ||
} | ||
} | ||
@@ -105,3 +106,3 @@ | ||
value: function has(key) { | ||
return this.cache[key] !== undefined; | ||
return key in this.cache; | ||
} | ||
@@ -134,6 +135,6 @@ }, { | ||
} | ||
} | ||
if (!silent && this.notify) { | ||
next(this.onchange("remove", this.dump())); | ||
if (!silent && this.notify) { | ||
next(this.onchange("remove", this.dump())); | ||
} | ||
} | ||
@@ -146,18 +147,25 @@ | ||
value: function set(key, value) { | ||
var obj = this.remove(key, true); | ||
var item = void 0; | ||
if (!obj) { | ||
obj = { | ||
if (this.has(key)) { | ||
item = this.cache[key]; | ||
item.value = value; | ||
item.next = null; | ||
item.previous = this.first; | ||
} else { | ||
if (++this.length > this.max) { | ||
this.remove(this.last, true); | ||
} | ||
if (this.length === 1) { | ||
this.last = key; | ||
} | ||
this.cache[key] = { | ||
next: null, | ||
previous: null, | ||
previous: this.first, | ||
value: value | ||
}; | ||
} else { | ||
obj.value = value; | ||
} | ||
obj.next = null; | ||
obj.previous = this.first; | ||
this.cache[key] = obj; | ||
if (this.first) { | ||
@@ -169,10 +177,2 @@ this.cache[this.first].next = key; | ||
if (!this.last) { | ||
this.last = key; | ||
} | ||
if (++this.length > this.max) { | ||
this.evict(); | ||
} | ||
if (this.notify) { | ||
@@ -179,0 +179,0 @@ next(this.onchange("set", this.dump())); |
{ | ||
"name": "tiny-lru", | ||
"description": "Tiny LRU cache for Client or Server", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"homepage": "https://github.com/avoidwork/tiny-lru", | ||
@@ -6,0 +6,0 @@ "author": "Jason Mulligan <jason.mulligan@avoidwork.com>", |
@@ -0,0 +0,0 @@ # Tiny LRU |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
13674
331