import
import copied to clipboard
Cache result with KV
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;
},
}
});