mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 16:49:06 +01:00
[json] add 'Clear schema cache' command. Fixes #138524
This commit is contained in:
@@ -21,7 +21,7 @@ interface CacheInfo {
|
||||
const MEMENTO_KEY = 'json-schema-cache';
|
||||
|
||||
export class JSONSchemaCache {
|
||||
private readonly cacheInfo: CacheInfo;
|
||||
private cacheInfo: CacheInfo;
|
||||
|
||||
constructor(private readonly schemaCacheLocation: string, private readonly globalState: Memento) {
|
||||
const infos = globalState.get<CacheInfo>(MEMENTO_KEY, {}) as CacheInfo;
|
||||
@@ -120,6 +120,27 @@ export class JSONSchemaCache {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public async clearCache(): Promise<string[]> {
|
||||
const uris = Object.keys(this.cacheInfo);
|
||||
try {
|
||||
const files = await fs.readdir(this.schemaCacheLocation);
|
||||
for (const file of files) {
|
||||
try {
|
||||
await fs.unlink(path.join(this.schemaCacheLocation, file));
|
||||
} catch (_e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
} finally {
|
||||
|
||||
this.cacheInfo = {};
|
||||
await this.updateMemento();
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
}
|
||||
function getCacheFileName(uri: string): string {
|
||||
return `${createHash('MD5').update(uri).digest('hex')}.schema.json`;
|
||||
|
||||
Reference in New Issue
Block a user