开发者

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));
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜