Skip to content

Batch static cache purge tags#193

Merged
timkelty merged 7 commits into
3.xfrom
timkelty/batch-static-cache-purges
Jul 24, 2026
Merged

Batch static cache purge tags#193
timkelty merged 7 commits into
3.xfrom
timkelty/batch-static-cache-purges

Conversation

@timkelty

@timkelty timkelty commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Collect static-cache purge tags until the request ends so file-heavy operations send a single gateway request instead of one request per file, while preserving explicit purgeTags() behavior. Fire the purge event once per send, defer overflow-tag handling until send time, and include saved-element fetch URLs when revalidation is needed.

Copilot AI review requested due to automatic review settings July 24, 2026 03:12

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.

Pull request overview

This PR batches static-cache purge tags and associated element context until the end of the request, reducing gateway calls during file-heavy operations while firing the purge event once per batch.

Changes:

  • Collect purge tags (and elements/fetch URLs) across operations and send them once via a single sendPurgeTagsRequest() call.
  • Update PurgeEvent to carry elements (array) instead of a single element, and adjust docs/tests accordingly.
  • Update CDN invalidation to enqueue purge tags (addPurgeTags) rather than triggering an immediate purge per file.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/unit/StaticCacheTest.php Updates unit tests to reflect batched sending and PurgeEvent::$elements.
src/StaticCache.php Implements purge batching, defers overflow handling until send time, and triggers the purge event once per batch.
src/fs/Fs.php Switches CDN invalidation to enqueue purge tags for batching.
src/events/PurgeEvent.php Changes event payload from element to elements array.
README.md Updates documentation for the new batched purge event semantics and elements payload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/StaticCache.php Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 03:17

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/StaticCache.php
Copilot AI review requested due to automatic review settings July 24, 2026 04:16

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/StaticCache.php
Copilot AI review requested due to automatic review settings July 24, 2026 04:22

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/StaticCache.php:121

  • The pending purge buffers (tagsToPurge, elementsToPurge, fetchUrls) are never cleared after the end-of-request send attempt. In long-running processes (e.g. queue daemon/worker), the StaticCache component can live across multiple requests/jobs, so this can cause stale tags/elements/URLs to be included in later purges and retain element objects in memory longer than necessary. Consider clearing these collections in a finally block after attempting to send (whether it succeeds, fails, or is canceled by the event).
        Craft::$app->onAfterRequest(function() {
            if ($this->tagsToPurge->isNotEmpty()) {
                try {
                    $this->sendPurgeTagsRequest(
                        $this->tagsToPurge,

Comment thread src/events/PurgeEvent.php Outdated
Comment thread README.md Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 05:53

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

README.md:226

  • The README says the before-purge event fires only for the “collected batch”, but sendPurgeTagsRequest() triggers StaticCache::EVENT_BEFORE_PURGE for any purge operation (including direct purgeTags() calls). It’s also worth calling out here that the event no longer includes element context.
The `StaticCache::EVENT_BEFORE_PURGE` event fires immediately before each tag purge, including the collected end-of-request batch. Listeners can modify its `tags` or cancel the purge.

src/events/PurgeEvent.php:14

  • The PR description mentions firing the purge event with its associated elements, but this PR removes element context from PurgeEvent entirely. If that’s intentional, the PR description should be updated to match the new API/behavior; otherwise, consider reintroducing element information in the event payload.
class PurgeEvent extends CancelableEvent
{
    /**
     * @var StaticCacheTag[] The static cache tags being purged.
     */
    public array $tags = [];
}

Comment thread src/events/PurgeEvent.php
Copilot AI review requested due to automatic review settings July 24, 2026 05:57

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/StaticCache.php
Copilot AI review requested due to automatic review settings July 24, 2026 06:00

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@timkelty
timkelty marked this pull request as ready for review July 24, 2026 06:07
@timkelty
timkelty merged commit 246d8df into 3.x Jul 24, 2026
10 checks passed
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