@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
60 lines (59 loc) • 3 kB
JavaScript
import { SplitsCacheInMemory } from './SplitsCacheInMemory';
import { MySegmentsCacheInMemory } from './MySegmentsCacheInMemory';
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
import { EventsCacheInMemory } from './EventsCacheInMemory';
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
/**
* InMemory storage factory for standalone client-side SplitFactory
*
* @param params - parameters required by EventsCacheSync
*/
export function InMemoryStorageCSFactory(params) {
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
var splits = new SplitsCacheInMemory(__splitFiltersValidation);
var rbSegments = new RBSegmentsCacheInMemory();
var segments = new MySegmentsCacheInMemory();
var largeSegments = new MySegmentsCacheInMemory();
var storage = {
splits: splits,
rbSegments: rbSegments,
segments: segments,
largeSegments: largeSegments,
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
impressionCounts: new ImpressionCountsCacheInMemory(),
events: new EventsCacheInMemory(eventsQueueSize),
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(splits, segments) : undefined,
uniqueKeys: new 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(),
largeSegments: new 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 === 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;
}
InMemoryStorageCSFactory.type = STORAGE_MEMORY;