1
1
import { ImpressionsCacheInMemory } from '../inMemory/ImpressionsCacheInMemory' ;
2
2
import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory' ;
3
3
import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory' ;
4
- import { IStorageFactoryParams , IStorageSync , IStorageSyncFactory } from '../types' ;
4
+ import { ISegmentsCacheSync , ISplitsCacheSync , IStorageFactoryParams , IStorageSync , IStorageSyncFactory } from '../types' ;
5
5
import { validatePrefix } from '../KeyBuilder' ;
6
6
import { KeyBuilderCS , myLargeSegmentsKeyBuilder } from '../KeyBuilderCS' ;
7
7
import { isLocalStorageAvailable } from '../../utils/env/isLocalStorageAvailable' ;
@@ -41,15 +41,15 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
41
41
const keys = new KeyBuilderCS ( prefix , matchingKey ) ;
42
42
const expirationTimestamp = Date . now ( ) - DEFAULT_CACHE_EXPIRATION_IN_MILLIS ;
43
43
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 ) ) ;
47
47
48
48
if ( settings . mode === LOCALHOST_MODE || splits . getChangeNumber ( ) > - 1 ) {
49
49
Promise . resolve ( ) . then ( onReadyFromCacheCb ) ;
50
50
}
51
51
52
- return {
52
+ const storage = {
53
53
splits,
54
54
segments,
55
55
largeSegments,
@@ -70,7 +70,7 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
70
70
} ,
71
71
72
72
// 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 {
74
74
75
75
return {
76
76
splits : this . splits ,
@@ -89,6 +89,18 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
89
89
} ;
90
90
} ,
91
91
} ;
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 ;
92
104
}
93
105
94
106
InLocalStorageCSFactory . type = STORAGE_LOCALSTORAGE ;
0 commit comments