mar*_*ujo 6 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;
Run Code Online (Sandbox Code Playgroud)
每个运营商都有自己的折扣,这些折扣因运营商而异,现在如果我更改数据库并需要清除所有运营商的折扣,我该怎么做?
我可以使用$ Cache-> clean(),但这将清除其他缓存(不仅仅是每个运算符的rebate缓存).如果我循环遍历所有运算符:
foreach($operator_codes AS $operator_code) {
$cache_key = 'getrebates_'.$operator_code;
$cache->delete($cache_key)
}
Run Code Online (Sandbox Code Playgroud)
这看起来像缓存的很多工作.有没有办法清除一部分缓存.
//Something like:
$section_key = 'getrebates';
$Cache[$section_key][$operator_code];
$Cache->clearSection($section_key);
Run Code Online (Sandbox Code Playgroud)
APC缓存是否有任何数组结构,还是基于缓存键/值?
the*_*uke 10
您可以将标记应用于存储在缓存中的值.这样,您可以轻松删除具有特定标记的所有缓存条目.
$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,
array('tagA', 'tagC')
);
Run Code Online (Sandbox Code Playgroud)
有关Zend_Cache_Core的clean方法的详细信息,请参阅此页面:http://framework.zend.com/manual/en/zend.cache.theory.html和API:http://framework.zend.com/apidoc/ 1.11 /