Skip to content

Commit d7e9f7d

Browse files
committed
IPersistentStore wrapper around IPersistentState
1 parent d36d75d commit d7e9f7d

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/client/pythonEnvironments/base/envsCache.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import { cloneDeep } from 'lodash';
55
import { IFileSystem } from '../../common/platform/types';
6-
import { IPersistentState } from '../../common/types';
7-
import { getGlobalPersistentStore } from '../common/externalDependencies';
6+
import { getGlobalPersistentStore, IPersistentStore } from '../common/externalDependencies';
87
import { areSameEnvironment, PartialPythonEnvironment } from '../info';
98
import { PythonEnvInfo } from './info';
109

@@ -58,7 +57,7 @@ export class PythonEnvInfoCache implements IEnvsCache {
5857

5958
private envsList: PythonEnvInfo[] | undefined;
6059

61-
private persistentStorage: IPersistentState<PythonEnvInfo[]> | undefined;
60+
private persistentStorage: IPersistentStore<PythonEnvInfo[]> | undefined;
6261

6362
constructor(private readonly isComplete: CompleteEnvInfoFunction) {}
6463

@@ -69,7 +68,7 @@ export class PythonEnvInfoCache implements IEnvsCache {
6968

7069
this.initialized = true;
7170
this.persistentStorage = getGlobalPersistentStore<PythonEnvInfo[]>('PYTHON_ENV_INFO_CACHE');
72-
this.envsList = this.persistentStorage?.value;
71+
this.envsList = this.persistentStorage?.get();
7372
}
7473

7574
public getAllEnvs(): PythonEnvInfo[] | undefined {
@@ -100,7 +99,7 @@ export class PythonEnvInfoCache implements IEnvsCache {
10099
const completeEnvs = this.envsList?.filter(this.isComplete);
101100

102101
if (completeEnvs?.length) {
103-
await this.persistentStorage?.updateValue(completeEnvs);
102+
await this.persistentStorage?.set(completeEnvs);
104103
}
105104
}
106105
}

src/client/pythonEnvironments/common/externalDependencies.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as fsapi from 'fs-extra';
55
import * as path from 'path';
66
import { ExecutionResult, IProcessServiceFactory } from '../../common/process/types';
7-
import { IPersistentState, IPersistentStateFactory } from '../../common/types';
7+
import { IPersistentStateFactory } from '../../common/types';
88
import { getOSType, OSType } from '../../common/utils/platform';
99
import { IServiceContainer } from '../../ioc/types';
1010

@@ -43,7 +43,17 @@ function getPersistentStateFactory(): IPersistentStateFactory {
4343
return internalServiceContainer.get<IPersistentStateFactory>(IPersistentStateFactory);
4444
}
4545

46-
export function getGlobalPersistentStore<T>(key: string): IPersistentState<T> {
46+
export interface IPersistentStore<T> {
47+
get(): T | undefined;
48+
set(value: T): Promise<void>;
49+
}
50+
51+
export function getGlobalPersistentStore<T>(key: string): IPersistentStore<T> {
4752
const factory = getPersistentStateFactory();
48-
return factory.createGlobalPersistentState<T>(key, undefined);
53+
const state = factory.createGlobalPersistentState<T>(key, undefined);
54+
55+
return {
56+
get() { return state.value; },
57+
set(value: T) { return state.updateValue(value); },
58+
};
4959
}

0 commit comments

Comments
 (0)