From 183b9ab119e66cda4e2987f1f04c285967c7633e Mon Sep 17 00:00:00 2001 From: cha0s Date: Wed, 30 Mar 2022 05:14:19 -0500 Subject: [PATCH] refactor: cache --- packages/resource/src/index.js | 7 +++++++ packages/resource/src/resource.js | 15 +++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/resource/src/index.js b/packages/resource/src/index.js index 8317863..cb26528 100644 --- a/packages/resource/src/index.js +++ b/packages/resource/src/index.js @@ -1,11 +1,18 @@ import {Hooks} from '@flecks/core'; +import {cache as resourceCache} from './resource'; + export {default as Resource} from './resource'; export * as JSONB from './jsonb'; export {default as JsonResource} from './json-resource'; export default { [Hooks]: { + '@flecks/core.hmr': (path) => { + if ('@avocado/resource' === path) { + resourceCache.reset(); + } + }, '@flecks/core.starting': (flecks) => { flecks.set('$avocado/resource.resources', flecks.gather( '@avocado/resource.resources', diff --git a/packages/resource/src/resource.js b/packages/resource/src/resource.js index 31992e8..e097deb 100644 --- a/packages/resource/src/resource.js +++ b/packages/resource/src/resource.js @@ -8,16 +8,11 @@ const { FLECKS_CORE_ROOT = process.cwd(), } = process.env; -const cache = 'production' === process.env.NODE_ENV - ? new LRU({ - length: (buffer) => buffer.length, - max: 16 * 1024 * 1024, - maxAge: Infinity, - }) - : { - has: () => {}, - set: () => {}, - }; +export const cache = new LRU({ + length: (buffer) => buffer.length, + max: 16 * 1024 * 1024, + maxAge: Infinity, +}); const decorate = compose( Property('uri'),