You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
329 B

4 years ago
  1. //
  2. 'use strict';
  3. function cacheWrapper (cache , key , fn ) {
  4. if (!cache) {
  5. return fn();
  6. }
  7. const cached = cache.get(key);
  8. if (cached !== undefined) {
  9. return cached;
  10. }
  11. const result = fn();
  12. cache.set(key, result);
  13. return result;
  14. }
  15. module.exports = cacheWrapper;