-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
Copy pathcloud-sketch-cache.ts
42 lines (35 loc) · 1.03 KB
/
cloud-sketch-cache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { FileStat } from '@theia/filesystem/lib/common/files';
import { injectable } from 'inversify';
import { toPosixPath } from '../../create/create-paths';
import { Create } from '../../create/typings';
@injectable()
export class SketchCache {
sketches: Record<string, Create.Sketch> = {};
fileStats: Record<string, FileStat> = {};
init(): void {
// reset the data
this.sketches = {};
this.fileStats = {};
}
addItem(item: FileStat): void {
this.fileStats[item.resource.path.toString()] = item;
}
getItem(path: string): FileStat | null {
return this.fileStats[path] || null;
}
purgeByPath(path: string): void {
for (const itemPath in this.fileStats) {
if (itemPath.indexOf(path) === 0) {
delete this.fileStats[itemPath];
}
}
}
addSketch(sketch: Create.Sketch): void {
const { path } = sketch;
const posixPath = toPosixPath(path);
this.sketches[posixPath] = sketch;
}
getSketch(path: string): Create.Sketch | null {
return this.sketches[path] || null;
}
}