[6.x] Fix Custom Invalidator background recache#15031
Open
marcorieser wants to merge 5 commits into
Open
Conversation
…ng background re-cache Fixes statamic#15025
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.
Fixes #15025
Problem
When
background_recacheis enabled, a customInvalidatorclass never runs itsinvalidate()logic on entry save.Invalidate::refreshEntry()callsInvalidator::refresh(). InDefaultInvalidator::refresh(), whenbackground_recachewas off, it delegated to$this->invalidate($item)— so a subclass overridinginvalidate()fired correctly. Whenbackground_recachewas on, it skippedinvalidate()entirely and recomputed URLs itself, calling$this->cacher->refreshUrls(...)directly. Any customInvalidatorsubclass overridinginvalidate()(the documented extension point) was silently never called in this mode.Fix
DefaultInvalidator::refresh()now always delegates throughinvalidate(), guarded by a$refreshingflag.invalidate()uses that flag to decide whether to callcacher->refreshUrls()(soft, background re-cache) orcacher->invalidateUrls()/cacher->flush()(hard invalidate), preserving existing behavior for both the default flow and deletions, while letting custom subclasses actually execute in all cases.The flag is set/reset around the delegated call via try/finally (so it can't get stuck on an exception) and saves/restores its previous value rather than resetting to
falseunconditionally (so nestedrefresh()/invalidate()calls, e.g. from a custom Invalidator that itself callsrefresh()on a related item, don't clobber an in-progress outer call).Tests
Added a unit test in
DefaultInvalidatorTest.phpasserting a custominvalidate()override is exercised whenbackground_recacheis enabled.