Skip to content

Add native cache invalidation - #206

Open
timkelty wants to merge 2 commits into
3.xfrom
native-cache-invalidation
Open

timkelty wants to merge 2 commits into
3.xfrom
native-cache-invalidation

Conversation

@timkelty

@timkelty timkelty commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Description

Use the Cloudflare invalidation endpoint for automatic static-cache tag invalidation instead of coupling invalidation to URL fetching. This removes fetchUrls collection and payload handling while preserving EVENT_BEFORE_PURGE and the existing Cache-Purge-Tag fallback when a web request fails.

Adds explicit invalidate-* console commands alongside the existing purge-* commands so hard purges remain available. The coordinated gateway invalidation endpoint must be deployed before this change.

Implementation thread: https://ampcode.com/threads/T-01a0fcfa-f02f-7279-bde1-e8d7ce2ef59b

timkelty and others added 2 commits October 2, 2026 15:24
Send automatic cache batches through the coordinated gateway invalidation endpoint while preserving explicit purge behavior and response-header fallback.

The gateway invalidate route must be deployed before this client change.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0fcfa-f02f-7279-bde1-e8d7ce2ef59b
Co-authored-by: Amp <amp@ampcode.com>
Add invalidate variants for the existing all, CDN, origin, prefix, and tag purge commands while keeping the explicit purge commands available.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0fcfa-f02f-7279-bde1-e8d7ce2ef59b
Co-authored-by: Amp <amp@ampcode.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 15:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T15:28:26.781612Z ca57f99 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca57f99a83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/StaticCache.php
{
$response = Craft::$app->getResponse();
$isWebResponse = $response instanceof \craft\web\Response;
$tags = $this->preparePurgeTags($tags, $isWebResponse);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve hard-purge headers during invalidation

When a web request already has a Cache-Purge-Tag header (for example, after calling purgeTags()) and also queues an automatic element or asset invalidation, this call tells preparePurgeTags() to merge that header into the invalidation batch and remove it from the response. On a successful cache/invalidate request, the explicit hard purge is therefore silently downgraded to an invalidation and never reaches the gateway as a purge header. The invalidation path should process only its supplied tags while preserving any existing hard-purge header.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Existing hard-purge headers can be downgraded to invalidations, and prefix invalidation lacks a request timeout.

Review effort: Balanced
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Adds native gateway cache invalidation while retaining explicit hard-purge operations and fallback headers.

Changes:

  • Routes automatic tag invalidation through cache/invalidate.
  • Adds tag/prefix invalidation APIs and CLI commands.
  • Updates tests and documentation for tag-only invalidation.
File Description
src/​StaticCache.php Implements native tag and prefix invalidation.
src/​cli/​controllers/​StaticCacheController.php Adds invalidate-* commands.
tests/​unit/​StaticCacheTest.php Tests invalidation payloads and fallback behavior.
tests/​unit/​StaticCacheControllerTest.php Covers purge and invalidation commands.
README.md Documents invalidation event behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/StaticCache.php
{
$response = Craft::$app->getResponse();
$isWebResponse = $response instanceof \craft\web\Response;
$tags = $this->preparePurgeTags($tags, $isWebResponse);
Comment thread src/StaticCache.php
Comment on lines +469 to +473
Helper::createGatewayApiClient()->request('POST', 'cache/invalidate', [
RequestOptions::JSON => [
'prefixes' => $urlPrefixes->values()->all(),
],
]);
Comment on lines +15 to +16
$module = Module::getInstance();
$environmentId = $this->environmentId();
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