[11.x] Make Cache::forget
compatible with Cache::flexible
#52859
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 #52847
Current Behavior
The
Cache::flexible
method, which implements the "stale-while-revalidate" pattern, currently creates two cache items:When
Cache::forget
is called, it only removes the main item, leaving the metadata item in place. This leads to unexpected behavior in the cache lifecycle.The issue
When
Cache::forget
is called, it only removes the main item, leaving the ":created" timestamp intact.On the next request,
Cache::flexible
finds anull
value for the main item but an existing ":created" timestamp.This causes the method to incorrectly assume the item is in the stale or expired state, rather than treating it as a fresh cache miss.
As a result, the cache remains null until the stale period is over, effectively breaking the expected cache regeneration behavior.
Current behavior
current_behavior.mov
Expected behavior
expected_behavior.mov
Proposed Fix
Update the
Cache::forget
method to remove both the main item and the associated metadata item when called on a key created byCache::flexible
.PoC
My PoC if you want to interactively test the issue.