(dev/core#174) CRM_Utils_Cache_Redis::flush() - Respect prefixes #12330
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.
Overview
When flushing caches for an instance of
CRM_Utils_Cache_Redis
, you shouldonly delete the items with the matching prefix.
For reference, consider this example:
If the system is generally configured for Redis, this will give us two instances of
CRM_Utils_Cache_Redis
-- these instances are stored on the same server but use different prefixes.Before
Flushing
js_strings
has the side-effect of flushing everything else in Redis, such ascommunity_messages
.After
Flushing
js_strings
only flushesjs_strings
.Comments
The example above focuses on two relatively obscure caches (
js_strings
andcommunity_messages
) because they actually exist today. In the future, as part of dev/core#174, it will become possible to store sessions in Redis. And then it will be more important -- e.g. if a user creates a custom-field, you do want to flush one set of data (e.g. the contact-fields cache), but you don't want to flush another (e.g. the user sessions).The current commit fixes Redis. Although it's outside the scope of this
commit, here's an assessment of other drivers:
APCcache
looks fine -- it already consults the prefix.ArrayCache
looks fine -- data is already scoped within the object.NoCache
looks fine -- it's a null-op for everything.SqlGroup
is loosely right. There's a similar-but-different quirk, but a separate PR will address that.Memcache
andMemcached
look buggy. I don't have these systems locally, so I haven't tested or patched.