Skip to content

Instantly share code, notes, and snippets.

@LogIN-
Created September 29, 2016 07:19
Show Gist options
  • Select an option

  • Save LogIN-/731ce729d867dbdd4c10a4c87b5d2cb4 to your computer and use it in GitHub Desktop.

Select an option

Save LogIN-/731ce729d867dbdd4c10a4c87b5d2cb4 to your computer and use it in GitHub Desktop.
Flush Magento Cache Programmatically by cache Type
<?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