UNPKG

ns2-front-module-common

Version:
79 lines 2.56 kB
/** * Модель структуры данных для кеширования в хранилищах */ var KeyValueCacheStructure = (function () { function KeyValueCacheStructure(expiration, _tags, _value) { this._expiredAt = 0; this._tags = []; this._value = null; this._hits = 0; this.expiredAt = expiration ? (Math.floor((new Date()).getTime()) + expiration) : 0; this.tags = _tags || []; this.value = _value || null; this.hits = 0; } Object.defineProperty(KeyValueCacheStructure.prototype, "expiredAt", { get: function () { return this._expiredAt; }, set: function (value) { this._expiredAt = value; }, enumerable: true, configurable: true }); Object.defineProperty(KeyValueCacheStructure.prototype, "hits", { get: function () { return this._hits; }, set: function (value) { this._hits = value; }, enumerable: true, configurable: true }); Object.defineProperty(KeyValueCacheStructure.prototype, "tags", { get: function () { return this._tags; }, set: function (value) { this._tags = value; }, enumerable: true, configurable: true }); Object.defineProperty(KeyValueCacheStructure.prototype, "value", { get: function () { return this._value; }, set: function (value) { this._value = value; }, enumerable: true, configurable: true }); KeyValueCacheStructure.prototype.serialize = function () { var obj = { expiredAt: this.expiredAt, tags: this.tags, value: this.value, hits: this.hits }; return JSON.stringify(obj); }; KeyValueCacheStructure.prototype.isExpired = function () { return ((this.expiredAt > 0) && (this.expiredAt > Math.floor((new Date()).getTime()))); }; KeyValueCacheStructure.unserialize = function (json) { var obj = JSON.parse(json); var expiredAt = obj.expiredAt || 0; var tags = obj.tags || []; var value = obj.value || null; var instance = new KeyValueCacheStructure(expiredAt, tags, value); instance.hits = obj.hits || 0; return instance; }; return KeyValueCacheStructure; }()); export { KeyValueCacheStructure }; //# sourceMappingURL=key-value-cache-structure.model.js.map