UNPKG

329 BJavaScriptView Raw
1//
2'use strict';
3
4function 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
19module.exports = cacheWrapper;