Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/common/cache.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
export class Cache<T> {
7
8
private static readonly enableDebugLogging = false;
9
10
private readonly _data = new Map<number, readonly T[]>();
11
private _idPool = 1;
12
13
constructor(
14
private readonly id: string
15
) { }
16
17
add(item: readonly T[]): number {
18
const id = this._idPool++;
19
this._data.set(id, item);
20
this.logDebugInfo();
21
return id;
22
}
23
24
get(pid: number, id: number): T | undefined {
25
return this._data.has(pid) ? this._data.get(pid)![id] : undefined;
26
}
27
28
delete(id: number) {
29
this._data.delete(id);
30
this.logDebugInfo();
31
}
32
33
private logDebugInfo() {
34
if (!Cache.enableDebugLogging) {
35
return;
36
}
37
console.log(`${this.id} cache size - ${this._data.size}`);
38
}
39
}
40
41