如何使用Memchached后端和Zend Framework有选择地清除缓存(使用标签或其他选项) [英] How to selectively clear cache (using tags or other option) with Memchached backend and Zend Framework
本文介绍了如何使用Memchached后端和Zend Framework有选择地清除缓存(使用标签或其他选项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们在Web项目中使用Memcached和Zend Framework.现在,我们需要使用 Zend_Cache API .
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.
不幸的是, memcached不支持标签.
我发现了以下解决方法:
I have found these workarounds:
- Memcached-tag项目.有人测试过吗?如何使用Zend实施?
- 像此问题中一样使用通配符,但似乎有点令人困惑,透明度较低,难以理解用Zend实施.
- 使用此实现或
- 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?
预先感谢
推荐答案
您是对的. Memcache不支持标签.
You're right. Memcache don't support tags.
您可以使用另一个键值来实现memcache的标签.
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
关于setTag方法& MemcacheTag:
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
这篇关于如何使用Memchached后端和Zend Framework有选择地清除缓存(使用标签或其他选项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文