n8n
Version:
n8n Workflow Automation Tool
28 lines • 911 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CachedMetricQuery = void 0;
class CachedMetricQuery {
constructor({ cacheService, cacheKey, ttlMs, query }) {
this.inFlight = null;
this.cacheService = cacheService;
this.cacheKey = cacheKey;
this.ttlMs = ttlMs;
this.query = query;
}
async get() {
this.inFlight ??= this.load().finally(() => {
this.inFlight = null;
});
return await this.inFlight;
}
async load() {
const cached = await this.cacheService.get(this.cacheKey);
if (cached !== undefined)
return cached;
const value = await this.query();
await this.cacheService.set(this.cacheKey, value, this.ttlMs);
return value;
}
}
exports.CachedMetricQuery = CachedMetricQuery;
//# sourceMappingURL=cached-metric-query.js.map