Repository navigation
Conversation
Consume the CMS checkpoint for browser/CDN policy and dependency tags, apply Cloud defaults before expiry caps, and preserve gateway tag invalidation. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c3c7-9d57-7547-959b-ebaf6c0cd15c Co-authored-by: Amp <amp@ampcode.com>
craftcms/cms#20545 was closed without merging, so drop the CacheControl service, middleware and event dependency. Collect element cache tags and expiry with ElementCaches, derive CDN-Cache-Control from the final response headers, purge on ElementCachesInvalidated and element save/delete through the signed gateway, and add the Clear Caches option and purge commands from 3.x. Lock craftcms/cms 6.x at 8a13417. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-6551416a-ce7c-4e90-adac-8c2edc72248c
Build on craftcms/cms#21032 instead of collecting element tags and expiry in Cloud's own middleware: - Hash tags with a TagEncoder and write Cache-Tag with a FOSHttpCache tag header formatter, so the header and purges match. - Make the signed gateway a FOSHttpCache ProxyClient (`cloud` driver), with soft purge as a client option, and purge through HttpCache::invalidator('cloud'). - Set Cloud's default lifetime as s-maxage inside TagResponse, so it's capped at element expiry, and copy the final lifetime to CDN-Cache-Control outside it, skipping responses the CachePolicy won't store and no-cache responses. Require craftcms/cms's timkelty/http-cache branch until #21032 merges. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
craftcms/cms#21032 now gives ResponseTagger the earliest element expiry as it's collected, so Cloud's default lifetime no longer has to be set inside TagResponse and restored afterward. CacheResponse sets CDN-Cache-Control to the page's own lifetime, or Cloud's default, capped at ResponseTagger::getExpiryDate(), and judges a response with its own CDN-Cache-Control header by that header. The `cloud` client needs no config entry now. Update craftcms/cms to 7283599. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
craftcms/cms#21032 now rejects no-cache responses in DefaultCachePolicy and defaults a client's driver to its name when an extend() creator exists, so drop Cloud's own no-cache check and the `driver` key from the soft_purge config. Update craftcms/cms to c16d739. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
craftcms/cms#21032 removed TagEncoder, so ResponseTagger hands the formatter raw tags. CacheTagHeaderFormatter now hashes them with CacheTagEncoder, a plain Cloud class, before truncating, and Gateway keeps hashing purges with the same class. Update craftcms/cms to 5cecafe. Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db Co-authored-by: Amp <amp@ampcode.com>
craftcms/cms#21032 now keeps only ResponseTagger, element tag collection and the expiry cap. CachePolicy, HttpCacheManager and the tag header moved to craftcms/http-cache, configured under `http-cache.*`. Require its main branch through a VCS repository and update imports and config keys. Update craftcms/cms to 157ef55. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
Update craftcms/cms to e147b17. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
Update to craftcms/cms 30bdbb8 (ResponseTagger is now Http\ResponseCacheInfo) and craftcms/http-cache ccc94d8 (CachePolicy is now CacheProfile). The package now invalidates element tags on the default client and sends invalidations after each request, command and job, so drop Cloud's own ElementCachesInvalidated listener and flush hooks. Gateway::flush() now throws FOSHttpCache's ExceptionCollection, so the package reports gateway failures instead of failing termination. Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db Co-authored-by: Amp <amp@ampcode.com>
craftcms/http-cache 1633ff5 reports any exception a client throws, so Gateway::flush() throws Laravel's exceptions as they are again. The package now invalidates element tags only on clients listed in `http-cache.clients`, so Cloud adds a `cloud` entry. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
craftcms/http-cache 79f089b invalidates element tags on the default client even without a config entry. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-4e830087-a857-4596-b578-0893eaf5a9db
Update craftcms/cms and craftcms/http-cache. Craft now flushes cache invalidations after database transactions commit, so the static cache tests register the database provider. Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f
Core's global RestrictCacheControl now caps lifetimes, so the README, the CacheResponse docblock and the test's copy of core's stack name it. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f
Craft sends no-cache headers again for actions without a lifetime of their own, so CacheResponse's comment says which requests are covered. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f
Core no longer sends no-cache headers for actions that set no lifetime, so CacheResponse skips the default for action requests itself. Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Core picks up #21032's fix for element expiry when an element's tag was collected first; http-cache's SendTagHeader now tags action responses. Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports Cloud's Craft 6 static caching (from
cache-control-model-port,fdf8c71) onto Craft'sCacheInfo(craftcms/cms#21032) and the craftcms/http-cache package. Craft collects the tags and caps lifetimes at element expiry. The package provides the cache profile, invalidation clients and tag header. Cloud only adds its tag wire format, its CDN header and its purge client.fdf8c71)CacheResponsecollected withElementCachesCollectCacheInfoandCacheInfo(getTags(),getExpiryDate())CacheTagsCacheTagEncoder, used by the formatter for the header and by the client for purgesCache-Tagheader and limitsCacheTags::header()CacheTagHeaderFormatter(a FOSTagHeaderFormatterthat hashes the raw tags fromCacheInfo), set ashttp-cache.tags.formatterCDN-Cache-ControlCdnCacheControl, always set,no-storefor personal responsesCacheResponse(global, first): the page's own lifetime, or Cloud's defaultpublic, max-age=1y, stale-while-revalidate=1h, capped atCacheInfo::getExpiryDate(). None whenCacheProfile::isResponseCacheable()rejects the response, includingno-cacheGatewayandStaticCachebuffersGatewayis a FOSProxyClient(Tag,Purge,Refresh,PrefixandClearCapable) registered as theclouddriver and default client. Callers purge raw tags and the client encodes them.'clients' => ['cloud' => ['soft_purge' => true]]sends tags tocache/invalidateThe package invalidates element tags on the default client (
cloud) and every other tag-capable client inhttp-cache.clients, and sends invalidations after each request, command and job. Cloud only adds URL purges for saved and deleted elements. The package reports gateway failures instead of failing termination.Important
Revert the composer pins once craftcms/cms#21032 lands and craftcms/http-cache is on Packagist.
craftcms/cmspoints atdev-timkelty/http-cacheandcraftcms/http-cacheatdev-main, both through VCS repositories.craftcms/cms-assetsis aliased (6.x-dev as dev-timkelty/http-cache) because the core branch requires it atself.version. The alias is inrequire-devsocomposer validate --strictpasses. Root aliases only apply to this repo's own installs either way.Behavior changes from
fdf8c71CDN-Cache-Controlinstead ofno-store, per the design ("Core speaks only standardCache-Control"). Cloudflare then follows theirCache-Control.RestrictCacheControlsends no-cache headers for them.Authorizationrequests don't get Cloud's default lifetime. An action that sets its own lifetime keeps it.Expires-only response (nopublic) isn't cached, because Symfony computesprivate, must-revalidatefor it.cloud:static-cache:purge-tagshashes its tags like every other tag purge.CDN-Cache-Controlheader the page sets, but only if the page'sCache-Controland the CDN header pass the same checks.Evidence
Contract tests in
tests/Feature/StaticCacheTest.phprun requests through core's globalCollectCacheInfoandRestrictCacheControland the route groups:hashes tags the same way in the Cache-Tag header and in purges: element andCacheInfotags in the header equal the tags POSTed to/cache/purge.gives pages without a cache policy Cloud's default, capped at element expiry:CDN-Cache-Control: max-age=90, …with an element expiring in 90 seconds, while the page'sCache-Controlstaysno-cache, private. Dropping the expiry cap fails it.sends no CDN-Cache-Control for responses a cache mustn't store:noCache(),no-store,no-cache,private,Set-Cookie, queued cookies, andSet-Cookiewith a lifetime.Related issues