tags:

views:

35

answers:

2

Hi, 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", can I say to memcache, something like delete->('user_54_*'); ? how? thanks :)

+1  A: 

No, but see the FAQ for a workaround: http://code.google.com/p/memcached/wiki/FAQ#Deleting_by_Namespace

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.

Emil Vikström
A: 

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