Magento Automatically Cache Refresh Using Cron.

0
232
views
Advertisement

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”.

<?php

//Cache Refresh Start

ini_set('max_execution_time', 18000); 

require_once 'app/Mage.php';

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

umask(0);

Mage::setIsDeveloperMode(true);

//Cache Refresh Start

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

foreach ($invalidatedTypes as $type) {

Mage::app()->getCacheInstance()->cleanType($type->getId());

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