@backland/schema
Version:
TypeScript schema declaration and validation library with static type inference
25 lines (24 loc) • 597 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.withCache = withCache;
var _utils = require("@backland/utils");
function withCache(parent) {
const cache = new Map();
function getOrSet(key, onCreate) {
if (!cache.has(key)) {
if (typeof onCreate !== 'function') {
throw new _utils.RuntimeError(`missing cache ${String(key)}`, {
cache,
parent
});
}
cache.set(key, onCreate());
}
return cache.get(key);
}
getOrSet.cache = cache;
return getOrSet;
}
//# sourceMappingURL=withCache.js.map