Skip to content

Instantly share code, notes, and snippets.

@dagolinuxoid
Created January 5, 2019 11:23
Show Gist options
  • Save dagolinuxoid/2738d845beae65a73874897441bdbf20 to your computer and use it in GitHub Desktop.
Save dagolinuxoid/2738d845beae65a73874897441bdbf20 to your computer and use it in GitHub Desktop.
alternative
let worker = {
slow(min, max) {
return min + max; // scary CPU-hogger is assumed
}
};
function cachingDecorator(fn){
const makeKey = input => String(input);
let cache = {};
return function wrap(...args) {
let key = makeKey(args);
if(!cache[key]) {
cache[key] = fn.apply(this, args);
}
return cache[key];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment