Skip to content

module: add a read-only mode to the compile cache - #65302

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:compile-cache-read-only
Open

module: add a read-only mode to the compile cache#65302
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:compile-cache-read-only

Conversation

@codebytere

Copy link
Copy Markdown
Member

A compile cache generated ahead of time and shipped inside an application package should only ever be read: the package may be immutable (an Electron app.asar, a read-only image) or covered by an integrity check, and a cache directory that appears at run time next to shipped code is a surprise either way. Today enabling the cache always implies writing: the tag directory is created on enable, and every module without an accepted entry is serialized and persisted at exit or on flushCompileCache().

This adds readOnly to module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1. With it, existing entries are looked up and loaded exactly as before; nothing is serialized into the in-memory store or written to disk, flushCompileCache() is a no-op, the write-permission check is skipped, and the cache directory is used as found rather than created, so enabling against a directory that does not exist fails (FAILED, with a message) instead of making one.

EnableOption becomes a small flag set (PORTABLE, READ_ONLY) since the two combine. Docs cover the option, the environment variable (cli.md, node.1) and a short section in module.md; test-compile-cache-api-readonly covers the missing-directory case, reading a previously generated cache without writing new entries, and the environment variable.

Context: same application as #65293 (an Electron app shipping its main-process cache in the package); review there asked that production launches never attempt writes.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 15, 2026
@codebytere
codebytere force-pushed the compile-cache-read-only branch from 7e1cda0 to 447fb62 Compare August 15, 2026 08:57
A compile cache generated ahead of time and shipped inside an
application package should only ever be read: the package may be
immutable or covered by an integrity check, and a cache directory that
appears at run time would be a surprise. Add readOnly to
module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1: existing
entries are loaded as before, nothing is serialized or persisted,
flushCompileCache() is a no-op, and the cache directory is used as found
rather than created, so enabling against a missing directory fails
instead of making one.

Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@codebytere
codebytere force-pushed the compile-cache-read-only branch from 447fb62 to 133e37b Compare August 15, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants