How to selectively clear cache (using tags or other option) with Memchached backend and Zend Framework

旧城冷巷雨未停 提交于 2019-12-12 14:51:58

问题


We use Memcached and Zend Framework in our web project. Now, we need to clean cache selectively using tags as specified in Zend_Cache API.

Unfortunately, memcached doesn't support tags.

I have found these workarounds:

  • Memcached-tag project. Has anybody tested it? How to implement it with Zend?
  • Use wildchards like in this question, but it seems a bit confusing, less transparent and harder to implement with Zend.
  • Use this implementation or this one, for supporting tags in Memcached, beeing aware of the drawbacks.
  • Any other option?

Thanks in advance


回答1:


You're right. Memcache don't support tags.

You can use another key-value to implement tag for memcache.

EX :

$this->objCache->save($arrResults, $strKey,array($strMyTag),$intCacheTime) // note : array($strMyTag) don't work for Memcache

MemcacheTag::setTag($strKey, $strMyTag) // our work around

About setTag Method & MemcacheTag:

function setTag($strKey,$strTag){

    $arrKey  = $cacheOjb->get($strTag);

    $arrKey[]= $strKey; 

}

function deleteCacheWithTag($strTag){

    $arrKey  = $cacheOjb->get($strTag);

    foreach ($arrKey as $strKey){

       $objCache->delete($strKey);

    }

}

This work around is quite simple and it works for my projects.

*Note: these codes need some modification, sorry for posting in a hurry



来源:https://stackoverflow.com/questions/24162415/how-to-selectively-clear-cache-using-tags-or-other-option-with-memchached-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!