Skip to content

[6.x] Fix old slug not removed from static cache when changing slugs#15021

Open
mynetx wants to merge 1 commit into
statamic:6.xfrom
mynetx:fix/static-cache-old-slug
Open

[6.x] Fix old slug not removed from static cache when changing slugs#15021
mynetx wants to merge 1 commit into
statamic:6.xfrom
mynetx:fix/static-cache-old-slug

Conversation

@mynetx

@mynetx mynetx commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

When you change an entry's slug with static caching enabled, the cached page for the old URL is never invalidated. With the full measure the old .html file stays on disk and keeps serving the stale page, so redirects to the new URL never get a chance to kick in.

The invalidator builds its URL list purely from the entry's current state, so the old URL is never part of it. Since EntrySaved is dispatched before the entry's dirty state is synced, the original slug is still available there. This PR rebuilds the old URI from the original slug (via UrlBuilder, so any route shape works) and invalidates it, plus a /old-url/* wildcard so pages cached beneath it (children of a renamed parent, mounted collections) are cleaned up too.

In background recache mode the old URLs are invalidated rather than refreshed, because they no longer resolve and a warm request could never replace them.

One known edge that is not covered: changing the slug and another route value (like the date) in the same save will rebuild the old URL with the new date. That felt like scope creep for this fix.

Verified against a local site with the full strategy: renaming a flat page, a nested page, and a parent with a cached child all remove the stale files now, where before they were left behind.

Fixes #14876

🤖 Generated with Claude Code

The invalidator only built URLs from the entry's current state, so after
a slug change the previously cached page kept being served at the old URL.
Rebuild the old URI from the original slug and invalidate it, along with
anything cached beneath it (descendants, mounted collections). In
background recache mode the old URLs are invalidated rather than
refreshed, since they no longer resolve and could never be recached.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Old slug not removed from static cache when changing slugs

1 participant