@inventivetalent/loading-cache
Version:
loading cache based on ben-manes/caffeine and node-cache
51 lines • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Caches = void 0;
const cache_1 = require("./cache");
class CacheBuilder {
constructor() {
this.options = {};
}
expireAfterAccess(expireAfterAccess) {
this.options.expireAfterAccess = expireAfterAccess;
return this;
}
expireAfterWrite(expireAfterWrite) {
this.options.expireAfterWrite = expireAfterWrite;
return this;
}
deleteOnExpiration(deleteOnExpiration) {
this.options.deleteOnExpiration = deleteOnExpiration;
return this;
}
expirationInterval(expirationInterval) {
this.options.expirationInterval = expirationInterval;
return this;
}
recordStats(recordStats) {
this.options.recordStats = recordStats;
return this;
}
build(loader, multiLoader, loadingInternalCache) {
if (typeof loader === "undefined") {
if (loadingInternalCache) {
return loadingInternalCache(this.options);
}
return new cache_1.SimpleCache(this.options);
}
return new cache_1.LoadingCache(this.options, loader, multiLoader, loadingInternalCache);
}
buildAsync(loader, multiLoader, loadingInternalCache) {
return new cache_1.AsyncLoadingCache(this.options, loader, multiLoader, loadingInternalCache);
}
}
class Caches extends CacheBuilder {
constructor() {
super();
}
static builder() {
return new CacheBuilder();
}
}
exports.Caches = Caches;
//# sourceMappingURL=Caches.js.map