Skip to content

Fix purging of pages that embed a cached include via SSI - #918

Merged
bencroker merged 1 commit into
putyourlightson:developfrom
karensg:fix-ssi-include-purge
Sep 15, 2026
Merged

bencroker merged 1 commit into
putyourlightson:developfrom
karensg:fix-ssi-include-purge

Conversation

@karensg

@karensg karensg commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Bug

With ssiEnabled and a reverse proxy purger (Cloudflare in our case), refreshing a cached include does not purge the pages that embed it. The include itself is refreshed and purged, but the reverse proxy keeps serving the previously assembled page until its TTL expires.

Cause: RefreshCacheService::getSsiIncludeSiteUris() derives the include index from an index query string param:

$queryString = parse_url($siteUri->uri, PHP_URL_QUERY) ?: '';
parse_str($queryString, $queryStringParams);
$index = $queryStringParams['index'] ?? null;

Since the cached include URI refactor in 5.12.0 (29177e4), cached include site URIs are stored as _cached_include_{index}?{cachedIncludePathParam}=_cached_include_{index}, so $index is always null, the SsiIncludeCacheRecord lookup matches nothing and no embedding pages are added to $purgeableSiteUris in refreshSiteUris().

Reproduction

Blitz 5.12.15 (and current develop), Craft 5.11.1, SSI enabled, Cloudflare purger.

  1. A page embeds craft.blitz.includeCached('counter.twig') whose template runs a tracked element query.
  2. Save a matching element. The include is cleared and regenerated locally.
  3. Blitz::$plugin->refreshCache->getSsiIncludeSiteUris([$includeSiteUri]), with the include's stored site URI, returns [] although blitz_ssiincludecaches has a row linking the include to the page.
  4. Cloudflare keeps serving the old assembled page (we observed age: 67816, a signature counter 300+ behind the origin).

Fix

  • Read the index from the _cached_include_ path prefix, the same way CacheRequestService detects cached includes, with a fallback to the legacy index query param for URIs created by versions before 5.12.0.
  • Return early when no include indexes were found, instead of running a query with an empty IN ().

Verified against our production records: the patched lookup returns the embedding page for both _cached_include_92856835?p=_cached_include_92856835 and the legacy _includes?action=blitz/include/cached&index=92856835.

Tests

Three Pest tests added to RefreshCacheTest: current URI format, legacy URI format, and a non-include URI. I could not run the Pest suite locally (it needs a Craft test install), so please run it on your side. ecs check passes on the changed files; phpstan reports only the pre-existing implicit-nullable notice on addElementQuery().

`RefreshCacheService::getSsiIncludeSiteUris()` derived the include index from
an `index` query string param. Since the cached include URI refactor in 5.12.0
the index lives in the path (`_cached_include_{index}?p=_cached_include_{index}`),
so the lookup never matched and pages embedding a refreshed include were not
purged from the reverse proxy.

The index is now read from the path prefix, falling back to the legacy query
string param, and the DB query is skipped when no include URIs are given.
@karensg
karensg force-pushed the fix-ssi-include-purge branch from ec8c69d to 6f1c490 Compare September 15, 2026 10:24
@bencroker
bencroker merged commit 51b3a48 into putyourlightson:develop Sep 15, 2026
@bencroker

Copy link
Copy Markdown
Collaborator

Thanks for the bug report and PR! Merged and released in 5.13.2.

@karensg
karensg deleted the fix-ssi-include-purge branch September 15, 2026 19:05
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