Commits
Michael Koch authored f093dce92b2
1 + | export class Cache<T> { |
2 + | private cache = new Set<T>(); |
3 + | |
4 + | add(item: T): void { |
5 + | this.cache.add(item); |
6 + | } |
7 + | |
8 + | has(item: T): boolean { |
9 + | return this.cache.has(item); |
10 + | } |
11 + | |
12 + | remove(item: T): void { |
13 + | this.cache.delete(item); |
14 + | } |
15 + | |
16 + | clear(): void { |
17 + | this.cache.clear(); |
18 + | } |
19 + | |
20 + | getAll(): T[] { |
21 + | return Array.from(this.cache); |
22 + | } |
23 + | |
24 + | forEach(callback: (item: T) => void): void { |
25 + | this.cache.forEach((item) => callback(item)); |
26 + | } |
27 + | } |
28 + |