I use Memcache to store content lists with very key combinations, when user edited the content, I must refresh the cache, but it is hard to say what particular list to refresh, it is not either a good idea to flush the entire Memcache server, so my question is: Can I group the Memcache keys so that I can flush a group and not the total Memcache?
Asked
Active
Viewed 931 times
1 Answers
1
You can't do this with one request only.
But you can loop on every keys using the same prefix to delete all of them like so :
$cache = new Memcached();
$keys = $cache->getAllKeys();
$prefix = "always_this_one_";
$prefixLength = strlen($prefix);
foreach ($keys as $key) {
if (substr_compare($key, $prefix, 0, $prefixLength) === 0) {
$cache->delete(substr($key, 0, -1));
}
}

Steve Chamaillard
- 1,691
- 1
- 11
- 20