Example 1:One object may have several attributes, every attribute is a key. A tag may contain all the keys. Then, if you want to delete all the keys of the Object, you just need to delete the tag.
<?php
$memcache = memcache_connect("127.0.0.1", 11211);
if ($memcache)
{
Example_Object EO;
$memcache->add("EO.attr_01", "EO.val_01");
$memcache->add("EO.attr_02", "EO.val_02");
$memcache->add("EO.attr_03", "EO.val_03");
$memcache->add("EO.attr_04", "EO.val_04");
$memcache->add("EO.attr_05", "EO.val_05");
$memcache->tag_add("tag", array("EO.attr_01", "EO.attr_02", "EO.attr_03", "EO.attr_04", "EO.attr_05"));
}
//... do something ...
$memcache->delete("tag");//all the attributs are deleted
else
{
echo "Connection to memcached failed";
}
?>
Example 2:There are a lot of vedios. In the past, we need to delete them one by one. But now, using tag function, we just need delete once.
<?php
$memcache = memcache_connect("127.0.0.1", 11211);
if ($memcache)
{
$memcache->add("vedio_01", "data_01");
$memcache->add("vedio_02", "data_02");
$memcache->add("vedio_03", "data_03");
$memcache->add("vedio_04", "data_04");
$memcache->add("vedio_05", "data_05");
$memcache->tag_add("tag_01", array("vedio_01", "vedio_02", "vedio_03", "vedio_04", "vedio_05"));
}
//... do something ...
$memcache->delete("tag_01");//all the videos are deleted
else
{
echo "Connection to memcached failed";
}
?>
|
很好,很强大,不过是不是把video写成vedio了?
shouldn't it be tag_delete instead of delete, because delete normally refers to a key and not to a tag?!
Example $memcache->tag_add("tag_01", array("vedio_01", "vedio_02", "vedio_03", "vedio_04", "vedio_05"));
Can I $memcache->tag_add("tag_01", "vedio_01"); $memcache->tag_add("tag_01", "vedio_02"); $memcache->tag_add("tag_01", "vedio_03"); $memcache->tag_add("tag_01", "vedio_04"); $memcache->tag_add("tag_01", "vedio_04");
with the same result?