with-promise-cache.js 496 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.withPromiseCache = withPromiseCache;
  6. function withPromiseCache(cache, fn, getKey) {
  7. return (...values)=>{
  8. const key = getKey ? getKey(...values) : values[0];
  9. let p = cache.get(key);
  10. if (!p) {
  11. p = fn(...values);
  12. p.catch(()=>cache.del(key));
  13. cache.set(key, p);
  14. }
  15. return p;
  16. };
  17. }
  18. //# sourceMappingURL=with-promise-cache.js.map