[8.x] TaggedCache flush should also remove tags from cache #39299
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.
At the moment flushing a tagged cache removes standard keys, forever keys and the key/value pair that was actually cached, but it leaves the tag itself as it only resets it.
In our project we use renoki-co/laravel-eloquent-query-cache and with heavy cache tag usage it leads to junk keys accumulating in our redis instance to a point where we now have close to 5 million keys that will never expire:
IMO, cache tags (as well as standard keys) should have an expiration time as well, but I'm able to solve that in userland by setting expiration time to them manually after caching the value. But it doesn't solve the issue when you flush a tag.
This PR solves flushing issue by deleting the tags from cache instead of resetting them. I've added a small test that you can run without TaggedCache changes and see that the tag key actually persists after flush.