标签:
<?php #缓存支持TAG标签实现 #为对TAG做分散存储,SO,TAG标签量不能太. $key="1000"; $val=array(/*big data*/); $tags=array("a","b"); $tag_key="my_tags_key"; #设置 $cval=array( $val, $tags ); $tagval=cache_get($tag_key); if(!is_array($tagval))$tagval=array(); foreach($tags as $v){ if(!isset($tagval[$v])) $tagval[$v]=array(); if(!in_array($key,$tagval[$v])) array_push($tagval[$v],$key); } cache_set($tag_key,$tagval); cache_set($key,$cval); #通过KEY获取数据 $val=cache_get($key); if(is_array($val)){ list($val,$tags)=$val; if(is_array($tags)&&count($tags)>0){ $tagval=cache_get($tag_key); foreach($tags as $v){ if(!isset($tagval[$v])||in_array($key,$tagval[$v])){ cache_delete($key); $val=null; break; } } } } #通过TAG获取数据 $tag="a"; $tagval=cache_get($tag_key); if(!is_array($tagval))$tagval=array(); $val=array(); if(isset($tagval[$tag])&&is_array($tagval[$tag])){ foreach($tagval[$tag] as $v){ $sval=cache_get($v); if($sval!=null)array_push($val,$sval); } } #通过key删除数据 cache_delete($key); #通过tag删除数据 $tag="a"; $tagval=cache_get($tag_key); if(!is_array($tagval))$tagval=array(); if(isset($tagval[$tag])&&is_array($tagval[$tag])){ foreach($tagval[$tag] as $v){ cache_delete($v); } }
标签:
原文地址:http://www.cnblogs.com/liushannet/p/5347510.html