1 | //
|
2 | ;
|
3 |
|
4 | function cacheWrapper (cache , key , fn ) {
|
5 | if (!cache) {
|
6 | return fn();
|
7 | }
|
8 |
|
9 | const cached = cache.get(key);
|
10 | if (cached !== undefined) {
|
11 | return cached;
|
12 | }
|
13 |
|
14 | const result = fn();
|
15 | cache.set(key, result);
|
16 | return result;
|
17 | }
|
18 |
|
19 | module.exports = cacheWrapper;
|