@@ -3,7 +3,7 @@ import Store from 'electron-store'
3
3
export default class CacheStore < ValueType , KeyType extends string = string > {
4
4
private readonly store : Store
5
5
private in_memory_store : Map < string , ValueType >
6
- private using_in_memory : boolean
6
+ private using_in_memory : number
7
7
private current_store : Store | Map < string , ValueType >
8
8
private readonly lifespan : number | null
9
9
@@ -20,7 +20,7 @@ export default class CacheStore<ValueType, KeyType extends string = string> {
20
20
clearInvalidConfig : true
21
21
} )
22
22
this . in_memory_store = new Map < string , ValueType > ( )
23
- this . using_in_memory = false
23
+ this . using_in_memory = 0
24
24
this . current_store = this . store
25
25
this . lifespan = max_value_lifespan
26
26
}
@@ -31,7 +31,7 @@ export default class CacheStore<ValueType, KeyType extends string = string> {
31
31
*/
32
32
public use_in_memory ( ) {
33
33
// Mirror store to memory map
34
- this . using_in_memory = true
34
+ this . using_in_memory += 1
35
35
this . in_memory_store = new Map ( this . store ) as Map < string , ValueType >
36
36
this . current_store = this . in_memory_store
37
37
}
@@ -85,8 +85,10 @@ export default class CacheStore<ValueType, KeyType extends string = string> {
85
85
public commit ( ) {
86
86
if ( this . using_in_memory ) {
87
87
this . store . store = Object . fromEntries ( this . in_memory_store )
88
- this . using_in_memory = false
89
- this . current_store = this . store
88
+ this . using_in_memory -= 1
89
+ if ( this . using_in_memory === 0 ) {
90
+ this . current_store = this . store
91
+ }
90
92
}
91
93
}
92
94
}
0 commit comments