• Mon. Dec 23rd, 2024

Node.js adds built-in API for on-disk caching

Byadmin

Sep 11, 2024



Node.js 22.8.0, the latest release of the event-driven JavaScript runtime, adds a JavaScript API to enable on-disk caching of all modules loaded after the API is called, presenting a caching option for code.

The API is called module.enable.CompileCache(). It overrides the NODE_COMPILE_CACHE environment variable, which only end users could use to enable on-disk caching. The new API lets tool and library authors manage the caching of their own code. The solution is a built-in alternative to v8-compile-cache packages, offering better performance and support for ESM (ECMAScript Modules).

Introduced on September 3, Node 22.8.0 can be downloaded from Nodejs.org. It is classified as a current release rather than an LTS (long-term support) release. With this update, Node now supports requiring code coverage to meet a specific threshold before a process successfully exits. Developers who want to use this capability must set the –experimental-test-coverage flag. Thresholds can be set for types of coverage including branch, function, and line coverages. Also in version 22.8.0, a flavor of vm.createContext() has been added to create a context without contextifying its global object when vm.constants.DONT_CONTEXTIFY is used. This is suitable when users want to freeze the context or speed up global access if they do not need the interceptor behavior.



Source link