我们在 Web 项目中使用 Memcached 和 Zend Framework。现在,我们需要使用 Zend_Cache API 中指定的标签有选择地清理缓存.
不幸的是,memcached doesn't support tags .
我找到了这些解决方法:
- Memcached-tag project .有人测试过吗?如何用 Zend 实现它?
- 像this question一样使用通配符, 但它似乎有点困惑,不太透明,更难用 Zend 实现。
- 使用this implementation或 this one ,用于支持 Memcached 中的标签,意识到缺点。
- 还有其他选择吗?
提前致谢
最佳答案
你是对的。 Memcache 不支持标签。
您可以使用另一个键值来为内存缓存实现标签。
例如:
$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:
function setTag($strKey,$strTag){
$arrKey = $cacheOjb->get($strTag);
$arrKey[]= $strKey;
}
function deleteCacheWithTag($strTag){
$arrKey = $cacheOjb->get($strTag);
foreach ($arrKey as $strKey){
$objCache->delete($strKey);
}
}
这个解决方法非常简单,适用于我的项目。
*注意:这些代码需要一些修改,抱歉匆忙发布
关于zend-framework - 如何使用 Memchached 后端和 Zend Framework 有选择地清除缓存(使用标签或其他选项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24162415/