3

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

不幸的是,memcached 不支持 tags

我找到了这些解决方法:

  • Memcached 标记项目。有人测试过吗?如何用 Zend 实现它?
  • 像在这个问题中那样使用通配符,但它似乎有点混乱,不太透明,而且很难用 Zend 实现。
  • 使用这个实现这个实现,以支持 Memcached 中的标签,并意识到这些缺点。
  • 还有其他选择吗?

提前致谢

4

1 回答 1

2

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

您可以使用另一个键值来为 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);

    }

}

这种解决方法非常简单,它适用于我的项目。

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

于 2014-07-16T07:42:33.947 回答