2

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?

Christophe
81.9k11 gold badges135 silver badges201 bronze badges
asked Nov 20, 2017 at 6:34

1 Answer 1

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));
 }
}
answered Nov 20, 2017 at 9:21
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.