cacheWrapper.js 329 B

12345678910111213141516171819
  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;