Skip to content

Worker: per-entrypoint Workers Caching via upload metadata exports #1401

Description

@agcty

What

Cloudflare's script-upload metadata now accepts a top-level exports map whose type: worker entries carry per-entrypoint cache configuration, overriding the worker-wide cache_options for a single entrypoint. Alchemy currently exposes only the worker-wide cache prop (WorkerCache = PutScriptMetadata.cacheOptions), and its exports prop is internal and admits only Durable Object and Workflow entries, so the documented gateway pattern (cache disabled on the default entrypoint, enabled on a named inner entrypoint) cannot be expressed.

Evidence

  • The live Cloudflare OpenAPI for PUT /accounts/{account_id}/workers/scripts/{script_name} (and the versions create endpoint, and /settings) documents metadata exports, with the example {"Admin": {"cache": {"enabled": true}, "type": "worker"}, "default": {"cache": {"enabled": false}, "type": "worker"}} and the description "Worker entrypoint entries (type: worker) carry cache configuration for that entrypoint."
  • Wrangler 4.112 sends it: its upload form builds metadata.exports from config (createWorkerUploadForm), and wrangler/config-schema.json defines WorkerEntrypointExport = { type: "worker", cache: { enabled: boolean } }.
  • @distilled.cloud/cloudflare@1.0.0-rc.4 already models per-entrypoint cache settings on the GET/response side, but PutScriptMetadata (and the versions-create metadata) has no exports field, so the value cannot be sent. The checked-in spec snapshot for the scripts update page predates the field: it references "a type: worker entry in the exports map" in the cache_options prose without defining the map itself; the live index.md for that page defines it fully.
  • Cloudflare's own Workers Caching docs recommend exactly this shape for gateways: https://developers.cloudflare.com/workers/cache/configuration/#per-entrypoint-caching

Why we need it

We run the documented gateway pattern in production: an authenticating default entrypoint that must execute on every request, and a cache-enabled named entrypoint serving published content. Worker-wide cache: { enabled: true } works (we ship it today, with every non-cached lane pinned no-store), but it also turns every ctx.exports loopback on the uncached lanes into billable requests and leaves the gateway behind an unnecessary cache layer. Per-entrypoint enablement is the intended fix and only the provider surface is missing.

Suggested shape

  1. distilled: refresh the workers scripts spec pages and regenerate, so PutScriptMetadata (and the versions-create metadata) gains exports?: Record<string, ...> including worker entries with cache?: { enabled: boolean }.
  2. alchemy: accept worker-entrypoint entries in the Worker resource (either by widening exports with a WorkerEntrypointExport mirroring wrangler's config schema, or a dedicated prop), merge them with the auto-populated Durable Object and Workflow exports, and pass them through both upload paths.

Happy to send the alchemy-side PR once the SDK field exists; the spec regen seemed better left to your pipeline than to a drive-by snapshot refresh.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions