Automatically refresh cache using cron in Magento.
Below script Is used to automatically refresh cache In Magento. This Script doesn’t refresh all the cache every time it will run, but it will refresh only an invalid cache which is required to refresh.
Following code gives you an array of invalid status of cache which is required to refresh.
$invalidatedTypes = Mage::app()->getCacheInstance()->getInvalidatedTypes();
Using the following line you can refresh a particular cache type by using its Id for example "block_html"
In the following code we have created a log file using following line.
Mage::log('Cache Type '.$type->getId()." Is Refresh.",null,'Cache_AutoRefresh.log');
So you can check the refreshed cache log on "Cache_AutoRefresh.log" file which is located in "var/log/Cache_AutoRefresh.log".
To automatically refresh cache you just need to create one file on Magento root folder. For Example: Autocroncache.php And Set Cron For "Autocroncache.php" File.
How To Set A Cron Job
1. First, open the Terminal.
2. Login with your SSH username & password.
Make sure you use your own domain name or IP address. If you want a user other than root, type that username before the @ symbol.
OR (IP address version)
OR (domain FTP user version)
3. Now type "crontab -e" after that command:
[root@current ~]#crontab -e
4. And Then Enter Following Command
Note: 30 12 indicates time 12:30, and * indicate that it should run every day of every month
/30 12 * * * sh /path/to/your/Autocroncache.php
5. Save and you are done.
Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. Our customers are companies of all sizes ranging from startups to large enterprises who realize that they need a professional internet solution to generate revenue streams, establish proper communication channels, to achieve desired goals and streamline business operations. [....] Read More