@@ -16,6 +16,7 @@ import type {ChartType, Interaction, RootProfilerData, Snapshot} from './Profile
16
16
const { List} = require ( 'immutable' ) ;
17
17
const { EventEmitter} = require ( 'events' ) ;
18
18
const { get, set} = require ( '../../utils/storage' ) ;
19
+ const LRU = require ( 'lru-cache' ) ;
19
20
20
21
const LOCAL_STORAGE_CHART_TYPE_KEY = 'profiler:selectedChartType' ;
21
22
const LOCAL_STORAGE_COMMIT_THRESHOLD = 'profiler:commitThreshold' ;
@@ -26,7 +27,7 @@ class ProfilerStore extends EventEmitter {
26
27
_bridge : Bridge ;
27
28
_mainStore : Object ;
28
29
29
- cachedData = { } ;
30
+ cachedData = LRU ( 50 ) ; // Evict items from the cache after this number
30
31
commitThreshold : number = ( ( get ( LOCAL_STORAGE_COMMIT_THRESHOLD , 0 ) : any ) : number ) ;
31
32
hideCommitsBelowThreshold : boolean = ( ( get ( LOCAL_STORAGE_HIDE_COMMITS_BELOW_THRESHOLD , false ) : any ) : boolean ) ;
32
33
isRecording : boolean = false ;
@@ -54,26 +55,26 @@ class ProfilerStore extends EventEmitter {
54
55
}
55
56
56
57
cacheDataForSnapshot ( snapshotIndex : number , snapshotRootID : string , key : string , data : any ) : void {
57
- this . cachedData [ `${ snapshotIndex } -${ snapshotRootID } -${ key } ` ] = data ;
58
+ this . cachedData . set ( `${ snapshotIndex } -${ snapshotRootID } -${ key } ` , data ) ;
58
59
}
59
60
60
61
cacheInteractionData ( rootID : string , data : any ) : void {
61
- this . cachedData [ `${ rootID } -interactions` ] = data ;
62
+ this . cachedData . set ( `${ rootID } -interactions` , data ) ;
62
63
}
63
64
64
65
clearSnapshots = ( ) => {
65
- this . cachedData = { } ;
66
+ this . cachedData . reset ( ) ;
66
67
this . processedInteractions = { } ;
67
68
this . rootsToProfilerData = new Map ( ) ;
68
69
this . emit ( 'profilerData' , this . rootsToProfilerData ) ;
69
70
} ;
70
71
71
72
getCachedDataForSnapshot ( snapshotIndex : number , snapshotRootID : string , key : string ) : any {
72
- return this . cachedData [ `${ snapshotIndex } -${ snapshotRootID } -${ key } ` ] || null ;
73
+ return this . cachedData . get ( `${ snapshotIndex } -${ snapshotRootID } -${ key } ` ) || null ;
73
74
}
74
75
75
76
getCachedInteractionData ( rootID : string ) : any {
76
- return this . cachedData [ `${ rootID } -interactions` ] || null ;
77
+ return this . cachedData . get ( `${ rootID } -interactions` ) || null ;
77
78
}
78
79
79
80
processInteraction ( interaction : Interaction ) : Interaction {
0 commit comments