Skip to content

module: implement flushCompileCache()

module: write compile cache to temporary file and then rename it

This works better in terms of avoiding race conditions.

Drive-by: throw instead of abort when module.enableCompileCache() gets passed a non-string argument.

module: implement flushCompileCache()

This implements an API for users to intentionally flush the accumulated compile cache instead of waiting until process shutdown. It may be useful for application that loads dependencies first and then either reload itself in other instances, or spawning other instances that load an overlapping set of its dependencies - in this case its useful to flush the cache early instead of waiting until the shutdown of itself.

Currently flushing is triggered by either process shutdown or user requests. In the future we should simply start the writes right after module loading on a separate thread, and this method only blocks until all the pending writes (if any) on the other thread are finished. In that case, the off-thread writes should finish long before any attempt of flushing is made so the method would then only incur a negligible overhead from thread synchronization.

Fixes: https://github.com/nodejs/node/issues/54770 Fixes: https://github.com/nodejs/node/issues/54465

Merge request reports

Loading