how to delete memcached data with "filter" keys?
I just want to delete cached data, but I have many keys, for example:
user_54_books
user_54_movies
user_54_comments
user_54_foobar
I can write $cache->delete('user_54_books');
but I have to do it with all "user_ID_objects"开发者_如何学C, can I say to memcache, something like delete->('user_54_*');
? how? thanks :)
No, but see “Deleting By Namespace” in the FAQ for a workaround.
Basically, you use a "version key". To delete all the old data, just increment the version key. The old data will thus don't be read anymore and will be old and overwritten when the space is needed.
Try this strategy:
$userIdList = array(1, 2, 3, 4, 5); $userIdObjectList = array("boots", "movies", "comments", "foobar"); foreach ($userIdList as $id) { foreach ($userIdObjectList as $object) { $cache->delete(sprintf("user_%s_%s", $id, $object)); } }
精彩评论