@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
47 lines (46 loc) • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryStorageFactory = void 0;
var DefinitionsCacheInMemory_1 = require("./DefinitionsCacheInMemory");
var SegmentsCacheInMemory_1 = require("./SegmentsCacheInMemory");
var ImpressionsCacheInMemory_1 = require("./ImpressionsCacheInMemory");
var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
var constants_1 = require("../../utils/constants");
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
var UniqueKeysCacheInMemory_1 = require("./UniqueKeysCacheInMemory");
var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
/**
* InMemory storage factory for standalone server-side SplitFactory
*
* @param params - parameters required by EventsCacheSync
*/
function InMemoryStorageFactory(params) {
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
var definitions = new DefinitionsCacheInMemory_1.DefinitionsCacheInMemory(__splitFiltersValidation);
var rbSegments = new RBSegmentsCacheInMemory_1.RBSegmentsCacheInMemory();
var segments = new SegmentsCacheInMemory_1.SegmentsCacheInMemory();
var storage = {
definitions: definitions,
rbSegments: rbSegments,
segments: segments,
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(definitions, segments) : undefined,
uniqueKeys: new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory(),
destroy: function () { }
};
// @TODO revisit storage logic in localhost mode
// No tracking data in localhost mode to avoid memory leaks
if (params.settings.mode === constants_1.LOCALHOST_MODE) {
var noopTrack = function () { return true; };
storage.impressions.track = noopTrack;
storage.events.track = noopTrack;
storage.impressionCounts.track = noopTrack;
storage.uniqueKeys.track = noopTrack;
}
return storage;
}
exports.InMemoryStorageFactory = InMemoryStorageFactory;
InMemoryStorageFactory.type = constants_1.STORAGE_MEMORY;