UNPKG

617 BJavaScriptView Raw
1export default class Cache {
2 constructor(delegate) {
3 this.delegate = delegate;
4 this.hits = 0;
5 this.misses = 0;
6 this.store = new Map();
7 }
8 get(key) {
9 const cacheKey = this.delegate.cacheKey(key);
10 let value = this.store.get(cacheKey);
11 if (value === undefined) {
12 this.misses++;
13 value = this.delegate.create(key);
14 this.store.set(cacheKey, value);
15 }
16 else {
17 this.hits++;
18 }
19 return value;
20 }
21 clear() {
22 this.store.clear();
23 }
24}
25//# sourceMappingURL=cache.js.map
\No newline at end of file