diff --git a/runtimes/nodejs/src/config.ts b/runtimes/nodejs/src/config.ts index 3991ffd15d..a2ee79583e 100644 --- a/runtimes/nodejs/src/config.ts +++ b/runtimes/nodejs/src/config.ts @@ -100,4 +100,8 @@ export default class Config { static get OSS_EXTERNAL_ENDPOINT(): string { return process.env.OSS_EXTERNAL_ENDPOINT } + + static get ENABLE_MODULE_CACHE(): boolean { + return process.env.ENABLE_MODULE_CACHE === 'true' || false + } } diff --git a/runtimes/nodejs/src/support/engine/module.ts b/runtimes/nodejs/src/support/engine/module.ts index 7ee0359a97..da49b799c0 100644 --- a/runtimes/nodejs/src/support/engine/module.ts +++ b/runtimes/nodejs/src/support/engine/module.ts @@ -1,3 +1,4 @@ +import Config from '../../config' import { FunctionCache } from './cache' import { FunctionContext } from './types' import { buildSandbox, createScript } from './utils' @@ -36,7 +37,9 @@ export class FunctionModule { ) // cache module - FunctionModule.cache.set(name, functionModule) + if (Config.ENABLE_MODULE_CACHE) { + FunctionModule.cache.set(name, functionModule) + } return functionModule } return require(name)