Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = ctx => {
const cache = new Cache();
// reset cache for watch mode
ctx.on('generateBefore', () => { cache.flush(); });
return function fragmentCache(id, fn) {
if (this.cache) return cache.apply(id, fn);
const result = fn();
cache.set(id, result);
return result;
};
};
constructor() {
this.cache = new Cache();
this.getters = {};
}