(dev/core#174) CRM_Utils_Cache_Redis::flush() - Respect prefixes
When flushing caches for an instance of `CRM_Utils_Cache_Redis`, you should
only delete the items with the matching prefix.
For example, we have two cache services for `js_strings` and
`community_messages`. These caches always use the same backend with
different naming/prefixes. The backend depends on the system configuration...
might be Redis, Memcache, or SqlGroup. Let's suppose the configuration is `Redis`.
To consider the before/after, it helps to have these two snippets for reference:
```
1: Civi::cache('js_strings')->flush();
2: Civi::cache('community_messages')->flush();
```
Before
------
Flushing `js_strings` has the side-effect of flushing everything
else in Redis, such as `community_messages`.
After
-----
Flushing `js_strings` only flushes `js_strings`.
Comments
--------
The example above focuses on two relatively obscure caches. 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`, `ArrayCache`, `NoCache` should be fine already.
* `SqlGroup` is sort of right, sort of not. Another patch will address that.
* `Memcache` and `Memcached` look like they have the same bug. I don't
have these systems locally, so I haven't tried to patch.