import icon indicating copy to clipboard operation
import copied to clipboard

Cache result with KV

Open ayoreis opened this issue 3 years ago • 1 comments

https://deno.land/[email protected]/runtime/kv

ayoreis avatar Dec 12 '22 16:12 ayoreis

I understand that cache should be applied here https://github.com/ayoreis/import/blob/7c0d89e604c11970c896ec83f6b4660bba1ac2f8/mod.ts#L144

Alternatively, I consider doing it on my side and wonder whether it's possible to store sealedExports instead of buildResult?

Currently I am using following code

      const { default: fn } = await importString(rawCode, {
        parameters: {
          dynamicImport: (moduleName) => dynamicImport(moduleName, {
            force: true,
          }),
        }
      });

Do you think its possible to modify my code like this and it will work?

    const cache = {};
      const { default: fn } = await importString(rawCode, {
        parameters: {
          dynamicImport: async (moduleName) => {
              if (cache[moduleName]) return cache[moduleName];
              const module = await dynamicImport(moduleName, {
            force: true,
          });
          cache[moduleName] = module;
          return module;
          },
        }
      });

7flash avatar Nov 12 '23 16:11 7flash