Skip to content

Instantly share code, notes, and snippets.

@vinioliveira
Last active December 18, 2015 02:29
Show Gist options
  • Select an option

  • Save vinioliveira/5711239 to your computer and use it in GitHub Desktop.

Select an option

Save vinioliveira/5711239 to your computer and use it in GitHub Desktop.
function cache_store(callback,key,value){}
function cache_retrieve(callback,key) {}
function slow_function(callback,input){}
function memorize(callback, slow_function) {
var self = this, result;
self.result = cache_retrieve(callback,slow_function);
if(!self.result)
{
self.result = function(cb, input){
value = slow_function.call(self, cb, input);
cache_store(self.callback,slow_function, value);
return value;
};
}
return self.result;
}
fast_function = memorise(slow_fucntion);
function cache_store(callback,key,value){}
function cache_retrieve(callback,key) {}
function slow_function(callback,input){}
function memorize(slow_function) {
var self = this, result;
cache_retrieve(function(value){
self.result = value;
},slow_function);
if(!result)
{
self.result = function(callback, input){
value = slow_function.call(self, callback, input);
cache_store(function(){},slow_function, value);
return value;
};
}
return self.result;
}
fast_function = memorise(slow_fucntion);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment