11import { ImpressionsCacheInMemory } from '../inMemory/ImpressionsCacheInMemory' ;
22import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory' ;
33import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory' ;
4- import { IStorageFactoryParams , IStorageSync , IStorageSyncFactory } from '../types' ;
4+ import { ISegmentsCacheSync , ISplitsCacheSync , IStorageFactoryParams , IStorageSync , IStorageSyncFactory } from '../types' ;
55import { validatePrefix } from '../KeyBuilder' ;
66import { KeyBuilderCS , myLargeSegmentsKeyBuilder } from '../KeyBuilderCS' ;
77import { isLocalStorageAvailable } from '../../utils/env/isLocalStorageAvailable' ;
@@ -41,15 +41,15 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
4141 const keys = new KeyBuilderCS ( prefix , matchingKey ) ;
4242 const expirationTimestamp = Date . now ( ) - DEFAULT_CACHE_EXPIRATION_IN_MILLIS ;
4343
44- const splits = new SplitsCacheInLocal ( settings , keys , expirationTimestamp ) ;
45- const segments = new MySegmentsCacheInLocal ( log , keys ) ;
46- const largeSegments = new MySegmentsCacheInLocal ( log , myLargeSegmentsKeyBuilder ( prefix , matchingKey ) ) ;
44+ const splits : ISplitsCacheSync = new SplitsCacheInLocal ( settings , keys , expirationTimestamp ) ;
45+ const segments : ISegmentsCacheSync = new MySegmentsCacheInLocal ( log , keys ) ;
46+ const largeSegments : ISegmentsCacheSync = new MySegmentsCacheInLocal ( log , myLargeSegmentsKeyBuilder ( prefix , matchingKey ) ) ;
4747
4848 if ( settings . mode === LOCALHOST_MODE || splits . getChangeNumber ( ) > - 1 ) {
4949 Promise . resolve ( ) . then ( onReadyFromCacheCb ) ;
5050 }
5151
52- return {
52+ const storage = {
5353 splits,
5454 segments,
5555 largeSegments,
@@ -70,7 +70,7 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
7070 } ,
7171
7272 // When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
73- shared ( matchingKey : string ) {
73+ shared ( matchingKey : string ) : IStorageSync {
7474
7575 return {
7676 splits : this . splits ,
@@ -89,6 +89,18 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
8989 } ;
9090 } ,
9191 } ;
92+
93+ // @TODO revisit storage logic in localhost mode
94+ // No tracking data in localhost mode to avoid memory leaks
95+ if ( params . settings . mode === LOCALHOST_MODE ) {
96+ const noopTrack = ( ) => true ;
97+ storage . impressions . track = noopTrack ;
98+ storage . events . track = noopTrack ;
99+ if ( storage . impressionCounts ) storage . impressionCounts . track = noopTrack ;
100+ if ( storage . uniqueKeys ) storage . uniqueKeys . track = noopTrack ;
101+ }
102+
103+ return storage ;
92104 }
93105
94106 InLocalStorageCSFactory . type = STORAGE_LOCALSTORAGE ;
0 commit comments