Skip to content

Add static page caching for Craft 6 on Cloud - #214

Closed
timkelty wants to merge 6 commits into
feature/craft-6-cloud-transformsfrom
cache-control-model
Closed

timkelty wants to merge 6 commits into
feature/craft-6-cloud-transformsfrom
cache-control-model

Conversation

@timkelty

@timkelty timkelty commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Craft 6 static page caching for Craft Cloud. The middleware derives CDN cache policy from the final response, tags cached pages with Craft cache tags, and purges those tags through the signed gateway API.

site response
  CacheResponse
    collect Craft cache tags
    derive CDN-Cache-Control
    set Cache-Tag

tag invalidation
  collect tags for the request or job
  queue PurgeStaticCache
  send signed gateway purge

Responses with authorization, session state, route or site tokens, or newly set cookies receive no-store. The Caches utility and cloud:purge provide explicit full, tag, and prefix purges.

This PR is stacked on #213 for RequestSigner. GitHub can retarget it to 5.x after #213 merges. Queued purges also depend on the planned Bref Laravel bridge SQS handler; until that lands, cloud:purge and the Caches utility run purges synchronously.

Evidence

  • Before: Craft 6 responses had no Craft Cloud CDN policy or cache tags, and Craft tag invalidations did not purge Cloud's static cache.
    After: StaticCacheTest covers cache lifetimes, opt-out conditions, tag collection, overflow tags, invalidation filtering, queued purges, the Caches utility, and cloud:purge.
  • PHP 8.5 CI passes.

Related issues

timkelty and others added 4 commits November 6, 2026 21:13
Ports 3.x's signed Cloudflare transform URLs to Craft 6's asset transform
driver registry, and registers a craftCloud transformer profile that
becomes the default on Cloud.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1b2a5-ffcf-7312-966f-7e8624cf8b79
Co-authored-by: Amp <amp@ampcode.com>
Core now picks transformers with a disk's asset_transformer key instead of
registered profiles (craftcms/cms#20542). Register the craft-cloud driver
with AssetTransformers, drop the craftCloud profile and the
defaultAssetTransformer switch, and detect Cloud storage from the asset's
own disk, so scoped disks work.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1b2a5-ffcf-7312-966f-7e8624cf8b79
Co-authored-by: Amp <amp@ampcode.com>
#20542 merged without the per-call transformer argument, so hand files that
aren't in Cloud's bucket straight to the craft driver. Drop the branch pin
and lock to 6.x at 8a13417.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1b2a5-ffcf-7312-966f-7e8624cf8b79
Co-authored-by: Amp <amp@ampcode.com>
@timkelty timkelty changed the title Integrate Cloud response caching with CMS cache-control policy Add Craft Cloud static caching for Craft 6 Nov 10, 2026
Design the driver on core's contract instead of porting 3.x: map core
parameters onto Cloudflare options, declare only the Cloudflare-only ones,
report output dimensions, and use the focal point only for crops, like the
craft driver. Sign with http-message-signatures directly, without 3.x's
query normalization, and add the asset's revision after signing, since the
gateway leaves v out of signatures. Trust each disk's asset_transformer
choice instead of checking the bucket, and hand only non-S3 disks to the
craft driver. Require craftcms/cms ^6.0.0-beta.1.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1b2a5-ffcf-7312-966f-7e8624cf8b79
Co-authored-by: Amp <amp@ampcode.com>
@timkelty
timkelty force-pushed the cache-control-model branch from fdf8c71 to c0d2bac Compare November 10, 2026 18:22
@timkelty
timkelty changed the base branch from 5.x to feature/craft-6-cloud-transforms November 10, 2026 18:22
@timkelty
timkelty force-pushed the cache-control-model branch from c0d2bac to 5f931b2 Compare November 10, 2026 18:24
Tag pages with their Craft cache tags and derive CDN-Cache-Control from
the final response headers. Purge on every TagDependency invalidation,
except drafts and revisions, with one queued PurgeStaticCache job per
request, command or queue job, signed with #213's RequestSigner. Add a
Clear Caches option and a single cloud:purge command.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-6551416a-ce7c-4e90-adac-8c2edc72248c
@timkelty
timkelty force-pushed the cache-control-model branch from 5f931b2 to 2f2afa4 Compare November 10, 2026 18:25
@timkelty timkelty changed the title Add Craft Cloud static caching for Craft 6 Add static page caching for Craft 6 on Cloud Nov 19, 2026
@timkelty
timkelty force-pushed the feature/craft-6-cloud-transforms branch 2 times, most recently from 3692144 to fbdc571 Compare December 5, 2026 16:10

timkelty commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #217, which rebuilds Cloud static caching on core's CacheInfo (craftcms/cms#21032) and craftcms/http-cache.

Follow-ups to check against #217. Each of these is in this PR, and I didn't find it in #217's description or file list:

  • The Caches utility option (cloud-static-cache) for a full purge from the control panel.
  • Queued purges: this PR batches them into one PurgeStaticCache job per request, command or job. Add Craft Cloud static caching on Craft's HTTP cache layer #217 sends them after termination through the package.
  • Purge filtering: this PR skips drafts, revisions and core's element-(index|search)-query::* tags. Check whether the package or core already does this.

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.

1 participant