UNPKG

771 BJavaScriptView Raw
1"use strict";
2module.exports = class Cache {
3 constructor() {
4 this.cache = new Map();
5 }
6 set(id, value) {
7 this.cache.set(id, value);
8 }
9 has(id) {
10 return this.cache.has(id);
11 }
12 get(id) {
13 return this.cache.get(id);
14 }
15 del(id) {
16 this.cache.delete(id);
17 }
18 apply(id, value) {
19 if (this.has(id))
20 return this.get(id);
21 if (typeof value === 'function')
22 value = value();
23 this.set(id, value);
24 return value;
25 }
26 flush() {
27 this.cache.clear();
28 }
29 size() {
30 return this.cache.size;
31 }
32 dump() {
33 return Object.fromEntries(this.cache);
34 }
35};
36//# sourceMappingURL=cache.js.map
\No newline at end of file