UNPKG

@splitsoftware/splitio-commons

Version:
64 lines (63 loc) 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InMemoryStorageCSFactory = void 0; var SplitsCacheInMemory_1 = require("./SplitsCacheInMemory"); var MySegmentsCacheInMemory_1 = require("./MySegmentsCacheInMemory"); 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 UniqueKeysCacheInMemoryCS_1 = require("./UniqueKeysCacheInMemoryCS"); var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory"); /** * InMemory storage factory for standalone client-side SplitFactory * * @param params - parameters required by EventsCacheSync */ function InMemoryStorageCSFactory(params) { var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation; var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation); var rbSegments = new RBSegmentsCacheInMemory_1.RBSegmentsCacheInMemory(); var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(); var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(); var storage = { splits: splits, rbSegments: rbSegments, segments: segments, largeSegments: largeSegments, 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(splits, segments) : undefined, uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(), destroy: function () { }, // When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key) shared: function () { return { splits: this.splits, rbSegments: this.rbSegments, segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(), largeSegments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(), impressions: this.impressions, impressionCounts: this.impressionCounts, events: this.events, telemetry: this.telemetry, uniqueKeys: this.uniqueKeys, destroy: function () { } }; }, }; // @TODO revisit storage logic in localhost mode // No tracking in localhost mode to avoid memory leaks: https://github.com/splitio/javascript-commons/issues/181 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.InMemoryStorageCSFactory = InMemoryStorageCSFactory; InMemoryStorageCSFactory.type = constants_1.STORAGE_MEMORY;