Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function memoize(fn, timeout) {
- let cache = null;
- let expire = Date.now() + timeout;
- return function() {
- if (!cache || Date.now() > expire) {
- return fn().then(data => {
- cache = data;
- expire = Date.now() + timeout;
- return data;
- });
- }
- return Promise.resolve(cache);
- }
- }
Add Comment
Please, Sign In to add comment