Magento Flush Everything Cache, Index, Images, JS, CSS in One Go

If you are developing a Magento store and you would like a method you can call to completely clear everything out that might be cached or indexed etc then you will like this little snippet:

public function flushEverything() {
        Mage::app()->getCacheInstance()->flush();
        Mage::getModel('core/design_package')->cleanMergedJsCss();
        Mage::getModel('catalog/product_image')->clearCache();
        $indexer    = Mage::getSingleton('index/indexer');
        /* @var $indexer Mage_Index_Model_Indexer */
        foreach($indexer->getProcessesCollection() as $process){
              $process->reindexEverything();
        }  
    }

This flushes the cache storage, removes merged JS/CSS files, flushes the product image cache then loops through each index and reindexes.

Perhaps overkill but sometimes there’s nothing like the use of excessive force!


Tags: flushmagentosnippetimagecachecodeindexjscssstorage