@daysnap/utils
Version:
23 lines (19 loc) • 489 B
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});// src/withCache.ts
function withCache(fn) {
const cache = {};
return function(...args) {
const key = JSON.stringify(args);
const hit = cache[key];
if (hit) {
return hit;
}
const res = fn(...args);
if (res instanceof Promise) {
return res.then((res2) => {
return cache[key] = res2;
});
}
return cache[key] = res;
};
}
exports.withCache = withCache;