We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a00f9b7 commit e061241Copy full SHA for e061241
src/cache.ts
@@ -2,13 +2,18 @@ export interface Clearable {
2
clear(): void;
3
}
4
export class Cache {
5
- #caches: Array<Clearable> = [];
+ #caches: Set<WeakRef<Clearable>> = new Set();
6
add(cache: Clearable): void {
7
- this.#caches.push(cache);
+ this.#caches.add(new WeakRef(cache));
8
9
clear(): void {
10
- for (const cache of this.#caches) {
11
- cache.clear();
+ for (const ref of this.#caches) {
+ const cache = ref.deref();
12
+ if (cache != null) {
13
+ cache.clear();
14
+ } else {
15
+ this.#caches.delete(ref);
16
+ }
17
18
19
0 commit comments