Skip to content

Instantly share code, notes, and snippets.

@questsin
Created February 20, 2019 14:56
Show Gist options
  • Save questsin/573bc4f780fe0c633e03dae7b15083f8 to your computer and use it in GitHub Desktop.
Save questsin/573bc4f780fe0c633e03dae7b15083f8 to your computer and use it in GitHub Desktop.
//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