Skip to content

@astrojs/cloudflare: cacheCloudflare() overrides an explicit cache.enabled: false in wrangler config #17375

Description

@skezo

Astro Info

Astro                    v7.0.9
Vite                     v8.1.4
Node                     v22.23.1
System                   Linux (x64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/cloudflare (v14.1.3)
Integrations             none

Describe the Bug

When a Cloudflare cache provider is configured (cache: { provider: cacheCloudflare() }), the adapter force-enables the Workers Cache in the emitted config even when the project's wrangler.jsonc explicitly sets "cache": { "enabled": false }. The built dist/server/wrangler.json comes out with "cache": { "enabled": true }, so the opt-out is silently rewritten.

The check at packages/integrations/cloudflare/src/wrangler.ts#L73 is

cache: needsWorkerCache && !config.cache?.enabled ? { enabled: true } : undefined,

and !config.cache?.enabled treats "unset" and "explicitly false" the same.

For context on why someone would set enabled: false while still using the provider: Workers Cache supports per-entrypoint enablement, e.g. "exports": { "Render": { "type": "worker", "cache": { "enabled": true } } } with the default export left uncached. That shape is useful for an uncached gateway that derives cache-key dimensions (host, region) into ctx.props and loops back into a cached named entrypoint via ctx.exports, which seems to be the documented way to add key dimensions the platform does not provide. The exports block passes through the customizer untouched; only the top-level enabled: false gets overridden. The workaround for now is post-processing dist/server/wrangler.json between build and deploy.

What's the expected result?

An explicit "cache": { "enabled": false } in the user's wrangler config survives the build. Checking for config.cache?.enabled === undefined rather than falsiness would keep the current auto-enable default for configs that do not mention cache at all, while respecting an explicit opt-out.

Link to Minimal Reproducible Example

https://github.com/skezo/astro-cf-repro/tree/cache-enabled-clobber

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)pkg: cloudflareRelated to the Cloudflare adaptertriage: fix verifiedReporter confirmed the triage bot fix works

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions