@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
44 lines (43 loc) • 1.62 kB
JavaScript
import { __extends } from "tslib";
import { AbstractMySegmentsCacheSync } from '../AbstractMySegmentsCacheSync';
/**
* Default MySegmentsCacheInMemory implementation that stores MySegments in memory.
* Supported by all JS runtimes.
*/
var MySegmentsCacheInMemory = /** @class */ (function (_super) {
__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));
export { MySegmentsCacheInMemory };