[6.x] Fix old slug not removed from static cache when changing slugs#15021
Open
mynetx wants to merge 1 commit into
Open
[6.x] Fix old slug not removed from static cache when changing slugs#15021mynetx wants to merge 1 commit into
mynetx wants to merge 1 commit into
Conversation
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>
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.
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
.htmlfile 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
EntrySavedis 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 (viaUrlBuilder, 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