The cache is a big concept, covering all aspects of the content, Magento cache is based on Zend, if you have a deep understanding of the Zend cache, I believe Magento cache is no longer talking, this article focuses on the flush Magento cache and flush Cache Storage The difference of two buttons;
To understand the difference between these two options, you should first understand something like how caching works in Magento. In particular, to be able to accurately understand IDs and tagging.
In essence, "id" is a unique string used to identify a record of shared storage in the cache. Tagging is another string used to classify data cached by different types of applications.
In Magento, tagging is primarily used to differentiate between the following cache types:
[Plain]View Plaincopy
- 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
Take a look at the default cache file list Storage example in Magento:
[Plain]View Plaincopy
- $ 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
As you can see, depending on the file name of the cache file, different cache modes may be divided.
Because the Magento cache is based on Zend cache, the Magento cache file will also have a default prefix mage, followed by an ID prefix (app/etc/hash is calculated for MD5, and then the first 3 characters are taken), Then there are tag tags and some other identifiers. The entire string constitutes the only ID of the cache entry.
Having understood the above, it is easy to understand what Magento did when you cleared the cache.
"Flush Magento Cache"
When you click "Flush Magento Cache", the background cachecontroller.php calls function Flushsystemaction (). In this function, the function of Mage_core_model_app's Cleancache () is called, and then the Mage_core_model_cache's Clean ($tags) function is called. , let's look at the definition of this function, and maybe we can find something:
[PHP]View Plaincopy
- /**
- * 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;
- }
We see that in this method it invokes some of the methods of the Zend cache object, but to point out that all caches matching the parameter $tags are cleared here, and if the $tags is empty, the else code snippet is executed, $tags defined in the Mage_core_model_ The APP and Mage_core_model_config, respectively, are Mage and Config, which means that all caches $tags to Mage and Config are cleared. So it didn't erase the entire cache.
Before looking at the Zend_cache "clean ()" function definition, look at what happened when you click on the other button "Flush Cache Storage".
"Flush Cache Storage"
When you click "Flush Cache Storage", the background cachecontroller.php calls function flushallaction () instead of the Flushsystemaction () mentioned earlier, The method will then instantiate a Mage_core_model_app object, but instead of calling clean ($tags), it calls Flush () and looks at the function:
[PHP]View Plaincopy
- /**
- * clean cached data by specific tag
- *
- * @return bool
- */
- Public function flush ()
- {  
- $res = $this->_frontend->clean ();
- return $res;
- }
Oh, I found a way to invoke the Zend Cache object without flush, but there is a difference where clean () does not pass any parameters; next go to Zend_cache_core::clean () to see what happened, when there is no incoming parameter $ tags in time.
[PHP]View Plaincopy
- /**
- * Clean Cache entries
- *
- * Available Modes is:
- * ' All ' (default) and remove all cache entries ($tags are not used)
- * ' old ' = remove too old cache entries ($tags are 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);
As you can see, when the clean parameter is empty, the $mode default is all, which clears all caches;
In addition, in the background cache Storage Management, select one or several cache type, then refresh, the principle is actually equivalent to "Flush Magento cache", here the cache type can be regarded as the incoming tag.
To summarize: "Flush Magento Cache" will clear the cache $tags as Mage and Config, not all caches, "flush Cache Storage" regardless of whether or not $tags all caches will be erased;
It is also important to note that when Magento uses the default file to store the cache, usually we can also use the RM-RF var/cache/* to clear the entire cache, but if not with the file cache, such as XCache, memcached, APC, DB, SQLite and so on, "Flush Magento Cache" may become invalid because memcached does not support tags, and so on. "Flush Cache Storage" may be more effective at this point.
If you use a shared cache system, such as two apps using a piece of memcached, using "Flush cache Storage" is not a sensible approach, so be careful!
Magento Cache Series Detailed: Clean cache