如何使用Memchached后端和Zend Framework有选择地清除缓存(使用标记或其他选项)

时间:2014-06-11 12:00:01

标签: zend-framework caching memcached zend-cache

我们在Web项目中使用Memcached和Zend Framework。现在,我们需要使用Zend_Cache API中指定的标记有选择地清理缓存。

不幸的是,memcached doesn't support tags

我找到了这些解决方法:

  • Memcached-tag project。有人测试过吗?如何用Zend实现它?
  • 使用像this question这样的野葛,但它似乎有点令人困惑,透明度较低,而且使用Zend更难实现。
  • 使用this implementationthis one来支持Memcached中的标记,了解其缺点。
  • 还有其他选择吗?

提前致谢

1 个答案:

答案 0 :(得分:2)

你是对的。 Memcache不支持标签。

您可以使用另一个键值来实现memcache的标记。

EX:

$ this-> objCache-> save($ arrResults,$ strKey,array($ strMyTag),$ intCacheTime)//注意:数组($ strMyTag)不适用于Memcache

MemcacheTag :: setTag($ strKey,$ strMyTag)//我们的工作

关于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);

}

}

这项工作非常简单,适用于我的项目。

*注意:这些代码需要一些修改,抱歉匆忙发布