UNPKG

@splitsoftware/splitio-commons

Version:
47 lines (46 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MySegmentsCacheInMemory = void 0; var tslib_1 = require("tslib"); var AbstractMySegmentsCacheSync_1 = require("../AbstractMySegmentsCacheSync"); /** * Default MySegmentsCacheInMemory implementation that stores MySegments in memory. * Supported by all JS runtimes. */ var MySegmentsCacheInMemory = /** @class */ (function (_super) { (0, tslib_1.__extends)(MySegmentsCacheInMemory, _super); function MySegmentsCacheInMemory() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.segmentCache = {}; return _this; } MySegmentsCacheInMemory.prototype.addSegment = function (name) { if (this.segmentCache[name]) return false; this.segmentCache[name] = true; return true; }; MySegmentsCacheInMemory.prototype.removeSegment = function (name) { if (!this.segmentCache[name]) return false; delete this.segmentCache[name]; return true; }; MySegmentsCacheInMemory.prototype.isInSegment = function (name) { return this.segmentCache[name] === true; }; MySegmentsCacheInMemory.prototype.setChangeNumber = function (changeNumber) { this.cn = changeNumber; }; MySegmentsCacheInMemory.prototype.getChangeNumber = function () { return this.cn || -1; }; MySegmentsCacheInMemory.prototype.getRegisteredSegments = function () { return Object.keys(this.segmentCache); }; MySegmentsCacheInMemory.prototype.getKeysCount = function () { return 1; }; return MySegmentsCacheInMemory; }(AbstractMySegmentsCacheSync_1.AbstractMySegmentsCacheSync)); exports.MySegmentsCacheInMemory = MySegmentsCacheInMemory;