"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CachedItem = void 0;
var CachedItem = /** @class */ (function () {
    function CachedItem(_a) {
        var _b = _a === void 0 ? {} : _a, ttl = _b.ttl;
        this.valid = false;
        this.ttlOptions = ttl;
        if (ttl && ttl.ttlInMs <= 0) {
            throw new Error('ttl.ttlInMs must be greater than 0');
        }
    }
    CachedItem.prototype.set = function (toCache) {
        this.cached = toCache;
        this.valid = true;
        this.lastSetItemTimestamp = Date.now();
    };
    CachedItem.prototype.isValid = function () {
        if (this.ttlOptions && this.lastSetItemTimestamp + this.ttlOptions.ttlInMs < Date.now()) {
            this.invalidate();
        }
        return this.valid;
    };
    CachedItem.prototype.get = function () {
        return this.isValid() ? this.cached : undefined;
    };
    CachedItem.prototype.invalidate = function () {
        this.valid = false;
    };
    return CachedItem;
}());
exports.CachedItem = CachedItem;
//# sourceMappingURL=cached-item.js.map