homebridge-nibe-s1156
Version:
Homebridge plugin for Nibe S1156
24 lines (23 loc) • 638 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cache = void 0;
class Cache {
constructor() {
this.store = {};
}
async get(key, ttl, unit, callback) {
const cacheValue = this.store[key];
if (cacheValue && cacheValue.ttl >= Date.now()) {
return cacheValue.value;
}
const value = await callback();
if (value) {
this.store[key] = {
ttl: Date.now() + (ttl * 1000 * (unit === 'MINUTES' ? 60 : 1)),
value: value,
};
}
return value;
}
}
exports.Cache = Cache;