Magento Automatically Cache Refresh Using Cron.

Hello Everyone Below Script Is Used To Refresh Automatically Cache In Magento. This Script Is’nt Refresh all the cache every time It’ll Run. But, It’s Refresh Only Invalide Cache Which Is Required To Refresh.

In Below Code I Have Create The Log File Using Following Line “Mage::log(‘Cache Type ‘.$type->getId().” Is Refresh.”,null,’Cache_AutoRefresh.log’);”. So You Can Check The Cache Refresh Log on “Cache_AutoRefresh.log” File Which Locate In “var/log/Cache_AutoRefresh.log”.


//Cache Refresh Start

ini_set('max_execution_time', 18000); 

require_once 'app/Mage.php';

$app = Mage::app('admin');



//Cache Refresh Start

$invalidatedTypes = Mage::app()->getCacheInstance()->getInvalidatedTypes();

foreach ($invalidatedTypes as $type) {


Mage::log('Cache Type '.$type->getId()." Is Refresh.",null,'Cache_AutoRefresh.log'); 


//Cache Refresh End


For Automatically Cache Refresh You Just Need To Create One File On Magento Root Folder For Example Autocroncache.php And Add This File On Cron.

Thanks for reading my blog. I hope it will help you, Please leave your comments here if it’s really help you. 🙂

Thank You :),
Mayank Zalavadia