Batch static cache purge tags#193
Merged
Merged
Conversation
There was a problem hiding this comment.
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
PurgeEventto carryelements(array) instead of a singleelement, 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.
There was a problem hiding this comment.
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 afinallyblock 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,
There was a problem hiding this comment.
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()triggersStaticCache::EVENT_BEFORE_PURGEfor any purge operation (including directpurgeTags()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
PurgeEvententirely. 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 = [];
}
timkelty
marked this pull request as ready for review
July 24, 2026 06:07
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.
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.