cacheWrapper.js 612 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.cacheWrapper = cacheWrapper;
  6. exports.cacheWrapperSync = cacheWrapperSync;
  7. async function cacheWrapper(cache, key, fn) {
  8. const cached = cache.get(key);
  9. if (cached !== undefined) {
  10. return cached;
  11. }
  12. const result = await fn();
  13. cache.set(key, result);
  14. return result;
  15. }
  16. function cacheWrapperSync(cache, key, fn) {
  17. const cached = cache.get(key);
  18. if (cached !== undefined) {
  19. return cached;
  20. }
  21. const result = fn();
  22. cache.set(key, result);
  23. return result;
  24. }
  25. //# sourceMappingURL=cacheWrapper.js.map