VM
script.createCachedData()
Creates a Buffer of compilation metadata. Cache bytes are an optimization for the matching script and runtime; handle rejected cache by recompiling. Tested on Node.js 22.16.0. Example output (one line per entry): ["true false 7"].
Formal Syntax & Structure
nodejs syntaxnodejs
script.createCachedData()Return Value
Buffer
Compilation cache bytes.
Working Example
Example Snippetnodejs
import { Script } from 'node:vm';const src = 'quantity + 2';const bytes = new Script(src).createCachedData();const s = new Script(src, { cachedData: bytes });console.log(Buffer.isBuffer(bytes), s.cachedDataRejected, s.runInNewContext({ quantity: 5 }, { timeout: 100 }));