Skip to content

src: add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE

Text for releasers:

This adds a new API module.enableCompileCache() that can be used to enable on-disk code caching of all modules loaded after this API is called. Previously this could only be enabled by the NODE_COMPILE_CACHE environment variable, so it could only set by end-users. This API allows tooling and library authors to enable caching of their own code. This is a built-in alternative to the v8-compile-cache/v8-compile-cache-lib packages, but have better performance and supports ESM.

In addition this adds module.getCompileCacheDir() to query the status of the compile cache, and a NODE_DISABLE_COMPILE_CACHE environment variable to disable the code cache. This serves as an escape hatch for end users to avoid unexpected/undesired effects of the compile cache (e.g. less precise test coverage).

When the module.enableCompileCache() method is invoked without a specified directory, Node.js will use the value of the NODE_COMPILE_CACHE environment variable if it's set, or defaults to path.join(os.tmpdir(), 'node-compile-cache') otherwise. Therefore it's recommended for tools to call this method without a directory argument to allow overrides.

Fixes: https://github.com/nodejs/node/issues/53639

Merge request reports

Loading