Created
January 5, 2019 11:23
-
-
Save dagolinuxoid/2738d845beae65a73874897441bdbf20 to your computer and use it in GitHub Desktop.
alternative
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
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