Skip to content

Instantly share code, notes, and snippets.

@lfborjas
Created September 17, 2011 01:37
Show Gist options
  • Save lfborjas/1223508 to your computer and use it in GitHub Desktop.
Save lfborjas/1223508 to your computer and use it in GitHub Desktop.
Javascript caching
var god = {
a: 1,
b: 2
};
var templater = (function(){
var cache = {};
return function(name){
if(cache[name]){
console.log("cached");
return cache[name];
}else{
cache[name] = god[name];
return god[name];
}
};
})();
console.log(templater('a'));
console.log(templater('a'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment