我们在 Web 项目中使用 Memcached 和 Zend Framework。现在,我们需要使用指定的标签有选择地清理缓存Zend_Cache API http://framework.zend.com/manual/1.10/en/zend.cache.theory.html#zend.cache.tags.
很遗憾,memcached 不支持标签 http://framework.zend.com/manual/1.10/en/zend.cache.backends.html#zend.cache.backends.memcached.
我找到了这些解决方法:
-
Memcached 标签项目 http://code.google.com/p/memcached-tag/。有人测试过吗?如何用Zend来实现呢?
- 使用通配符,例如这个问题 https://stackoverflow.com/questions/1595904/memcache-and-wildcards,但它似乎有点令人困惑,不太透明,并且更难用 Zend 实现。
- Use 这个实现 http://framework.zend.com/issues/browse/ZF-4253 or this one https://github.com/bigwhoop/taggable-zend-memcached-backend/blob/master/src/TrekkSoft/Cache/TaggableZendMemcachedBackend.php,了解 Memcached 中支持标签的缺点。
- 还有其他选择吗?
提前致谢
你说得对。 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:
function setTag($strKey,$strTag){
$arrKey = $cacheOjb->get($strTag);
$arrKey[]= $strKey;
}
function deleteCacheWithTag($strTag){
$arrKey = $cacheOjb->get($strTag);
foreach ($arrKey as $strKey){
$objCache->delete($strKey);
}
}
这个解决方法非常简单,并且适用于我的项目。
*注意:这些代码需要一些修改,抱歉匆忙发布
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)