zend-framework – 清除Zend Cache的模式

前端之家收集整理的这篇文章主要介绍了zend-framework – 清除Zend Cache的模式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我开始使用Zend Cache(APC后端),并且在返回缓存值方面都很好,而不是每次都访问数据库.但是,继承人我的问题:
$cache_key = 'getrebates_'.$operator_code;

if(PP_Model_CacheService::exists($cache_key)) {
    $cached_values = PP_Model_CacheService::load($cache_key);
} else {
   //hits the db    
   $cached_values = $this->getAll($operator_code);
   PP_Model_CacheService::save($cached_values,$cache_key);
}
return $cached_values;

每个操作符都有自己的折扣,这些折扣因操作符而异,现在如果我更改数据库并需要清除所有操作符的折扣,我该怎么做?

我可以使用$Cache-> clean(),但这将清除其他缓存(不仅仅是每个运算符的rebate缓存).如果我循环遍历所有运算符:

foreach($operator_codes AS $operator_code) {
   $cache_key = 'getrebates_'.$operator_code;
   $cache->delete($cache_key)
}

这看起来像缓存的很多工作.有没有办法清除一部分缓存.

//Something like:
$section_key = 'getrebates';
$Cache[$section_key][$operator_code];
$Cache->clearSection($section_key);

APC缓存是否有任何数组结构,还是基于缓存键/值?

您可以将标记应用于存储在缓存中的值.这样,您可以轻松删除具有特定标记的所有缓存条目.
$cache->save($huge_data,'myUniqueID',array('tagA','tagB'));

// clear all cache entries with tag tagA or tagC
$cache->clean(
  Zend_Cache::CLEANING_MODE_MATCHING_TAG,'tagC')
);

有关Zend_Cache_Core:http://framework.zend.com/apidoc/1.11/的clean方法的详细信息,请参阅此页面http://framework.zend.com/manual/en/zend.cache.theory.html和API

原文链接:https://www.f2er.com/php/132719.html

猜你在找的PHP相关文章