Created
February 20, 2019 14:56
-
-
Save questsin/573bc4f780fe0c633e03dae7b15083f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LRU Cache | |
//https://github.com/monsur/jscache | |
//https://github.com/rsms/js-lru | |
//todo: transposition table, LRU Cache, WithMemory | |
//var Cache = new Object(); // or just {} | |
// show the values stored | |
//for (var k in Cache) { | |
// use hasOwnProperty to filter out keys from the Object.prototype | |
// if (Cache.hasOwnProperty(k)) { | |
// alert('key is: ' + k + ', value is: ' + Cache[k]); | |
// } | |
//} | |
//alert(Cache.length); | |
/* simple cache with no memory management */ | |
var Cache = {}; | |
function set(key,obj){ //put | |
Cache[key] = obj; | |
return key; | |
} | |
function get(key){ | |
if (Cache.hasOwnProperty(key)) { | |
return Cache[key]; | |
} else { | |
return undef; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment