@@ -91,6 +91,11 @@ export interface IStorageMain extends IDisposable {
91
91
*/
92
92
delete ( key : string ) : void ;
93
93
94
+ /**
95
+ * Whether the storage is using in-memory persistence or not.
96
+ */
97
+ isInMemory ( ) : boolean ;
98
+
94
99
/**
95
100
* Close the storage connection.
96
101
*/
@@ -111,7 +116,7 @@ abstract class BaseStorageMain extends Disposable implements IStorageMain {
111
116
private readonly _onDidCloseStorage = this . _register ( new Emitter < void > ( ) ) ;
112
117
readonly onDidCloseStorage = this . _onDidCloseStorage . event ;
113
118
114
- private _storage : IStorage = new Storage ( new InMemoryStorageDatabase ( ) ) ; // storage is in-memory until initialized
119
+ private _storage = new Storage ( new InMemoryStorageDatabase ( ) , { hint : StorageHint . STORAGE_IN_MEMORY } ) ; // storage is in-memory until initialized
115
120
get storage ( ) : IStorage { return this . _storage ; }
116
121
117
122
abstract get path ( ) : string | undefined ;
@@ -130,6 +135,10 @@ abstract class BaseStorageMain extends Disposable implements IStorageMain {
130
135
super ( ) ;
131
136
}
132
137
138
+ isInMemory ( ) : boolean {
139
+ return this . _storage . isInMemory ( ) ;
140
+ }
141
+
133
142
init ( ) : Promise < void > {
134
143
if ( ! this . initializePromise ) {
135
144
this . initializePromise = ( async ( ) => {
@@ -188,7 +197,7 @@ abstract class BaseStorageMain extends Disposable implements IStorageMain {
188
197
return storage . init ( ) ;
189
198
}
190
199
191
- protected abstract doCreate ( ) : Promise < IStorage > ;
200
+ protected abstract doCreate ( ) : Promise < Storage > ;
192
201
193
202
get items ( ) : Map < string , string > { return this . _storage . items ; }
194
203
@@ -281,10 +290,10 @@ class BaseProfileAwareStorageMain extends BaseStorageMain {
281
290
super ( logService , fileService ) ;
282
291
}
283
292
284
- protected async doCreate ( ) : Promise < IStorage > {
293
+ protected async doCreate ( ) : Promise < Storage > {
285
294
return new Storage ( new SQLiteStorageDatabase ( this . path ?? SQLiteStorageDatabase . IN_MEMORY_PATH , {
286
295
logging : this . createLoggingOptions ( )
287
- } ) ) ;
296
+ } ) , ! this . path ? { hint : StorageHint . STORAGE_IN_MEMORY } : undefined ) ;
288
297
}
289
298
}
290
299
@@ -359,12 +368,12 @@ export class WorkspaceStorageMain extends BaseStorageMain {
359
368
super ( logService , fileService ) ;
360
369
}
361
370
362
- protected async doCreate ( ) : Promise < IStorage > {
371
+ protected async doCreate ( ) : Promise < Storage > {
363
372
const { storageFilePath, wasCreated } = await this . prepareWorkspaceStorageFolder ( ) ;
364
373
365
374
return new Storage ( new SQLiteStorageDatabase ( storageFilePath , {
366
375
logging : this . createLoggingOptions ( )
367
- } ) , { hint : wasCreated ? StorageHint . STORAGE_DOES_NOT_EXIST : undefined } ) ;
376
+ } ) , { hint : this . options . useInMemoryStorage ? StorageHint . STORAGE_IN_MEMORY : wasCreated ? StorageHint . STORAGE_DOES_NOT_EXIST : undefined } ) ;
368
377
}
369
378
370
379
private async prepareWorkspaceStorageFolder ( ) : Promise < { storageFilePath : string ; wasCreated : boolean } > {
@@ -420,7 +429,7 @@ export class InMemoryStorageMain extends BaseStorageMain {
420
429
return undefined ; // in-memory has no path
421
430
}
422
431
423
- protected async doCreate ( ) : Promise < IStorage > {
424
- return new Storage ( new InMemoryStorageDatabase ( ) ) ;
432
+ protected async doCreate ( ) : Promise < Storage > {
433
+ return new Storage ( new InMemoryStorageDatabase ( ) , { hint : StorageHint . STORAGE_IN_MEMORY } ) ;
425
434
}
426
435
}
0 commit comments