Created
September 29, 2016 07:19
-
-
Save LogIN-/731ce729d867dbdd4c10a4c87b5d2cb4 to your computer and use it in GitHub Desktop.
Flush Magento Cache Programmatically by cache Type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function flushMagentoCache(){ | |
| $flushCacheStart = microtime(true); | |
| $cacheTypes = array(); | |
| $cacheTypes[] = 'config'; | |
| $cacheTypes[] = 'layout'; | |
| $cacheTypes[] = 'block_html'; | |
| $cacheTypes[] = 'translate'; | |
| $cacheTypes[] = 'collections'; | |
| $cacheTypes[] = 'eav'; | |
| $cacheTypes[] = 'config_api'; | |
| $cacheTypes[] = 'config_api2'; | |
| for ($i = 0; $i < sizeof($cacheTypes); $i++): | |
| try { | |
| \Mage::app()->getCacheInstance()->cleanType($cacheTypes[$i]); | |
| \Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => $cacheTypes[$i])); | |
| } catch (Exception $ex) { | |
| Logger::write()->error('+++Flushing cache failure+++', $ex->getMessage()); | |
| } | |
| endfor; | |
| $flushCacheEnd = microtime(true); | |
| $flushCacheTotalSec = round($flushCacheEnd - $flushCacheStart, 2); | |
| $flushCacheTotalMin = round(($flushCacheEnd - $flushCacheStart) / 60, 2); | |
| echo('==> Flush Cache time : ' . $flushCacheTotalMin . ' (min), '.$flushCacheTotalSec . ' (sec)'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment