cache是一个很大的概念,涉及的内容方方面面,magento cache是基于zend的,如果你对zend cache理解很深的话,相信magento cache也不再话下,本篇文章着重介绍Flush Magento Cache 和Flush Cache Storage 两个按钮的区别;
为了理解这两个选项之间的区别,你要先了解一些东西如缓存如何在 Magento 中工作。特别是要能准确的理解ids 和 tagging。
实质上,"id"就是一个唯一的字符串用来标识高速缓存中的共享存储的记录。tagging是另一个字符串,用于对不同类型的应用程序缓存的数据进行分类。Configuration (non-layout XML files) Layouts (all those XML files under app/design/…) Blocks HTML output (Page blocks like headers, footers and callouts) Translations Collections Data EAV types and attributes (reduces some database lookups) Web Services Configuration
$ ls var/cache/mage--0 mage---1ef_DB_PDO_MYSQL_DDL_catalog_product_index_price_idx_1 mage---1ef_DB_PDO_MYSQL_DDL_core_config_data_1 mage---1ef_LAYOUT_0183D2D163E71FE45BB4CE3F4045A71BD mage---1ef_LAYOUT_0659E64C667F785D2436DB04EBCBEE12E mage---1ef_LAYOUT_088A9AF9EA75F3D59B57387F8E9C7D7A6 mage---1ef_LAYOUT_0956CDEF59F213D48A2D1218CC2CD1E96 mage---1ef_LAYOUT_1013A059DA3EFFB6F31EB8ABA68D0469E mage---1ef_LAYOUT_12D7604E9632FF8D14B782A248FCBD2E7 mage---1ef_LAYOUT_14E2F46FB273D9CEA54FDD1B14EB28645 mage---1ef_LAYOUT_16CD0CCB23CB5ABE6844B7E3241F0A751 mage---1ef_LAYOUT_1DC0705D40BBC39A32179EE8A85BEF5D7 mage---1ef_Zend_LocaleC_en_US_day_gregorian_format_wide_wed mage---1ef_Zend_LocaleC_en_US_month_gregorian_format_wide_5
/** * Clean cached data by specific tag * * @param array $tags * @return bool */ public function clean($tags=array()) { $mode = Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG; if (!empty($tags)) { if (!is_array($tags)) { $tags = array($tags); } $res = $this->_frontend->clean($mode, $this->_tags($tags)); } else { $res = $this->_frontend->clean($mode, array(Mage_Core_Model_App::CACHE_TAG)); $res = $res && $this->_frontend->clean($mode, array(Mage_Core_Model_Config::CACHE_TAG)); } return $res; }
/** * Clean cached data by specific tag * * @return bool */ public function flush() { $res = $this->_frontend->clean(); return $res; }
/** * Clean cache entries * * Available modes are : * 'all' (default) => remove all cache entries ($tags is not used) * 'old' => remove too old cache entries ($tags is not used) * 'matchingTag' => remove cache entries matching all given tags * ($tags can be an array of strings or a single string) * 'notMatchingTag' => remove cache entries not matching one of the given tags * ($tags can be an array of strings or a single string) * 'matchingAnyTag' => remove cache entries matching any given tags * ($tags can be an array of strings or a single string) * * @param string $mode * @param array|string $tags * @throws Zend_Cache_Exception * @return boolean True if ok */ public function clean($mode = 'all', $tags = array()) { if (!$this->_options['caching']) { return true; } if (!in_array($mode, array(Zend_Cache::CLEANING_MODE_ALL, Zend_Cache::CLEANING_MODE_OLD, Zend_Cache::CLEANING_MODE_MATCHING_TAG, Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG, Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG))) { Zend_Cache::throwException('Invalid cleaning mode'); } self::_validateTagsArray($tags); return $this->_backend->clean($mode, $tags);
如果你使用共享缓存系统,如两个apps使用一块memcached,用“Flush Cache Storage”并不是一个明智的办法,所以要小心使用!
magento缓存系列详解:如何cache一个block
原创文章,转载请注明出处,本文链接http://blog.csdn.net/shangxiaoxue/article/details/7601355!