simple-lru-cache
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
/** | ||
@@ -12,2 +14,11 @@ * LRU cache based on a double linked list | ||
ListElement.prototype.setKey = function(key){ | ||
this.key = key | ||
} | ||
ListElement.prototype.setValue = function(value){ | ||
this.value = value | ||
} | ||
function Cache(options){ | ||
@@ -31,2 +42,6 @@ if(!options) | ||
var cacheVal = this.cache[key] | ||
/* | ||
* Define if the egt function should hit the value to move | ||
* it to the head of linked list | ||
*/ | ||
hit = hit != undefined && hit != null ? hit : true; | ||
@@ -42,3 +57,9 @@ if(cacheVal && hit) | ||
var actual = this.cache[key] | ||
hit = hit != undefined && hit != null ? hit : true; | ||
/* | ||
* Define if the set function should hit the value to move | ||
* it to the head of linked list | ||
*/ | ||
hit = hit != undefined && hit != null ? hit : true; | ||
if(actual){ | ||
@@ -48,11 +69,28 @@ actual.value = val | ||
}else{ | ||
var cacheVal = new ListElement(undefined,undefined,key,val) | ||
var cacheVal | ||
if(this.size >= this.maxSize){ | ||
var tailKey = this.tail.key | ||
this.detach(this.tail) | ||
/* | ||
* If max is reached we'llreuse object to minimize GC impact | ||
* when the objects are cached short time | ||
*/ | ||
cacheVal = this.cache[tailKey] | ||
delete this.cache[tailKey] | ||
cacheVal.next = undefined | ||
cacheVal.before = undefined | ||
/* | ||
* setters reuse the array object | ||
*/ | ||
cacheVal.setKey(key) | ||
cacheVal.setValue(val) | ||
} | ||
cacheVal = cacheVal ? cacheVal : new ListElement(undefined,undefined,key,val) | ||
this.cache[key] = cacheVal | ||
this.attach(cacheVal) | ||
} | ||
if(this.size>this.maxSize){ | ||
var tailKey = this.tail.key | ||
this.detach(this.tail) | ||
delete this.cache[tailKey] | ||
} | ||
} | ||
@@ -59,0 +97,0 @@ |
{ | ||
"name": "simple-lru-cache", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Gabriel Eisbruch", | ||
@@ -18,7 +18,7 @@ "description": "", | ||
"type": "MIT", | ||
"url": "https://github.com/mercadolibre/node-simple-lru-cache/blob/master/LICENSE" | ||
"url": "https://github.com/geisbruch/node-simple-lru-cache/blob/master/LICENSE" | ||
}], | ||
"repositories": [{ | ||
"type": "git", | ||
"url" : "http://github.com/mercadolibre/node-simple-lru-cache.git" | ||
"url" : "http://github.com/geisbruch/node-simple-lru-cache.git" | ||
}], | ||
@@ -25,0 +25,0 @@ "dependencies": { |
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
10688
12
263