Skip to content

fix(cache): store Web Cache under origin data - #36145

Merged
nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:fix/web-cache-storage-dir
Jul 20, 2026
Merged

nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:fix/web-cache-storage-dir

Conversation

@nathanwhit

Copy link
Copy Markdown
Member

Summary

  • store Cache API data beneath Deno's origin-data directory
  • reject redirected final cache directories and use owner-only Unix modes
  • update deno info output and cover the persisted location end to end

Details

The Web Cache implementation stored its SQLite metadata and response bodies in
a system temporary directory, independently of the selected Deno cache and
origin-data location. This also made otherwise persistent Cache API state
subject to temporary-directory lifecycle.

Cache API state now lives under <DENO_DIR>/location_data/web_cache, with the
existing storage-key hash separating individual stores. Directory setup
validates the final path before opening the database.

Validation

  • ./tools/format.js --check
  • cargo test -p deno_cache cache_storage_dir
  • cargo test -p deno_lib cache_storage_dir_is_under_origin_data
  • cargo test -p integration_tests --test integration -- web_cache_is_stored_under_deno_dir --nocapture
  • cargo test -p integration_tests --test integration -- cache_put_overwrite --nocapture
  • cargo test -p specs_tests --test specs -- info::flag --nocapture
  • cargo test -p specs_tests --test specs -- info::json --nocapture
  • cargo check -p deno_lib -p deno_cache
  • cargo clippy -p deno_cache --tests -- -D warnings

AI assistance was used to help implement and test this change.

@bartlomieju bartlomieju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correct, well-scoped, and consistent with existing invariants. A few optional notes below.

Correctness

  • The origin_data_folder_path.unwrap() invariant matches the pre-existing origin_storage_dir code directly above it, so this reuses an established invariant rather than adding a new panic path. 👍
  • Both worker factories are updated and the only other caller (cli/tools/info.rs) is too — no stragglers on the old signature.
  • In info.rs, web_cache_dir is intentionally computed from the un-suffixed origin_dir (before the --location hash is applied), so the displayed root matches the real on-disk root. Consistent, just worth a second glance.

Security / robustness (optional)

  • The symlink check guards only the leaf component; create_dir_all will still traverse a symlinked intermediate (e.g. if web_cache itself were a symlink). Fine as defense-in-depth under DENO_DIR, but a one-line comment noting the leaf-only scope would help future readers.
  • set_permissions(0o700) is re-applied on every open (idempotent, harmless — arguably desirable). Note it applies only to the leaf hash dir; the web_cache parent is created with default umask.

Migration note (not a bug)

  • Existing caches in $TMPDIR/deno_cache are silently orphaned — a one-time effective cache reset. Inherent to the fix and fine, but worth a line in the changelog/PR description so it isn't mistaken for corruption.

Tests look great — the permissions test pre-loosens to 0o777 to prove the tightening happens, and tempfile is correctly a dev-dependency.

@nathanwhit
nathanwhit merged commit 01c89b8 into denoland:main Jul 20, 2026
136 checks passed
bartlomieju pushed a commit that referenced this pull request Jul 23, 2026
## Summary

- store Cache API data beneath Deno's origin-data directory
- reject redirected final cache directories and use owner-only Unix
modes
- update `deno info` output and cover the persisted location end to end

## Details

The Web Cache implementation stored its SQLite metadata and response
bodies in
a system temporary directory, independently of the selected Deno cache
and
origin-data location. This also made otherwise persistent Cache API
state
subject to temporary-directory lifecycle.

Cache API state now lives under `<DENO_DIR>/location_data/web_cache`,
with the
existing storage-key hash separating individual stores. Directory setup
validates the final path before opening the database.

## Validation

- `./tools/format.js --check`
- `cargo test -p deno_cache cache_storage_dir`
- `cargo test -p deno_lib cache_storage_dir_is_under_origin_data`
- `cargo test -p integration_tests --test integration --
web_cache_is_stored_under_deno_dir --nocapture`
- `cargo test -p integration_tests --test integration --
cache_put_overwrite --nocapture`
- `cargo test -p specs_tests --test specs -- info::flag --nocapture`
- `cargo test -p specs_tests --test specs -- info::json --nocapture`
- `cargo check -p deno_lib -p deno_cache`
- `cargo clippy -p deno_cache --tests -- -D warnings`

AI assistance was used to help implement and test this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants