-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInMemoryStorage.ts
More file actions
50 lines (43 loc) · 2.03 KB
/
InMemoryStorage.ts
File metadata and controls
50 lines (43 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { SplitsCacheInMemory } from './SplitsCacheInMemory';
import { SegmentsCacheInMemory } from './SegmentsCacheInMemory';
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
import { EventsCacheInMemory } from './EventsCacheInMemory';
import { IStorageFactoryParams, IStorageSync } from '../types';
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
import { UniqueKeysCacheInMemory } from './UniqueKeysCacheInMemory';
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
/**
* InMemory storage factory for standalone server-side SplitFactory
*
* @param params - parameters required by EventsCacheSync
*/
export function InMemoryStorageFactory(params: IStorageFactoryParams): IStorageSync {
const { settings: { scheduler: { impressionsQueueSize, eventsQueueSize, }, sync: { __splitFiltersValidation } } } = params;
const splits = new SplitsCacheInMemory(__splitFiltersValidation);
const rbSegments = new RBSegmentsCacheInMemory();
const segments = new SegmentsCacheInMemory();
const storage = {
splits,
rbSegments,
segments,
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
impressionCounts: new ImpressionCountsCacheInMemory(),
events: new EventsCacheInMemory(eventsQueueSize),
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(splits, segments) : undefined,
uniqueKeys: new UniqueKeysCacheInMemory(),
destroy() { }
};
// @TODO revisit storage logic in localhost mode
// No tracking data in localhost mode to avoid memory leaks
if (params.settings.mode === LOCALHOST_MODE) {
const noopTrack = () => true;
storage.impressions.track = noopTrack;
storage.events.track = noopTrack;
storage.impressionCounts.track = noopTrack;
storage.uniqueKeys.track = noopTrack;
}
return storage;
}
InMemoryStorageFactory.type = STORAGE_MEMORY;