lru
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -9,2 +9,6 @@ var LRU = exports.LRU = function (max) { | ||
LRU.prototype.set = function (key, value) { | ||
key += ''; | ||
if (key in this.cache) { | ||
return this.cache[key].value = value; | ||
} | ||
this.cache[key] = { | ||
@@ -28,2 +32,3 @@ next: null | ||
LRU.prototype.get = function (key) { | ||
key += ''; | ||
var element = this.cache[key]; | ||
@@ -33,2 +38,5 @@ if (!element) { | ||
} | ||
if (this.head === key) { | ||
return element.value; | ||
} | ||
if (element.next) { | ||
@@ -35,0 +43,0 @@ this.cache[element.next].prev = element.prev; |
{ "name" : "lru", | ||
"description" : "A simple O(1) LRU cache", | ||
"version" : "0.1.0", | ||
"version" : "0.1.1", | ||
"author" : "Chris O'Hara <cohara87@gmail.com>", | ||
@@ -5,0 +5,0 @@ "main" : "index", |
@@ -16,5 +16,5 @@ **A simple LRU cache supporting O(1) set, get and eviction of old keys** | ||
cache.set('foo', bar'); | ||
cache.set('foo', 'bar'); | ||
cache.get('foo'); //=> bar | ||
``` | ||
5668
5
129