I would like to refresh all cache at specified intervals, like once a day at midnight (as an example). How can I accomplish this?
I'm using CE 1.9.1.
I would like to refresh all cache at specified intervals, like once a day at midnight (as an example). How can I accomplish this?
I'm using CE 1.9.1.
If in your magento system,magento cron jobs are working properly
then
you define a cronjob
which fire on midnight and clear cache.
<crontab>
<jobs>
<clean_cache_midnight><!-- identifier -->
<schedule>
<cron_expr>0 0 * * *</cron_expr> <!-- run cronjob on midnight -->
</schedule>
<run>
<model>MyModule_Model_Group_Class_Name::functionName</model>
</run>
</clean_cache_midnight>
</jobs>
</crontab>
And class is
<?php
class [ModuleNameSpace]_[ModuleName]_Model_Mycron
{
public function functionName(){
/**
* Flush all magento cache
*/
Mage::app()->cleanCache();
}
}
create config.xml
at app/code/community/Amit/Cleancache/etc/
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Amit_Cleancache>
<version>1.0.0</version>
</Amit_Cleancache>
</modules>
<global>
<models>
<cleancache>
<class>Amit_Cleancache_Model</class>
</cleancache>
</models>
</global>
<crontab>
<jobs>
<clean_cache_midnight><!-- identifier -->
<schedule>
<cron_expr>0 0 * * *</cron_expr> <!-- running cronjob on midnight -->
</schedule>
<run>
<model>cleancache/Fire::fireCacheonMidnight</model>
</run>
</clean_cache_midnight>
</jobs>
</crontab>
</config>
File2: create Fire.php
at app/code/community/Amit/Cleancache/Model/
code:
<?php
class Amit_Cleancache_Model_Fire
{
public function fireCacheonMidnight(){
/**
* Flush all magento cache
*/
Mage::app()->cleanCache();
}
}
File3: module config file Amit_Cleancache.xml at app/etc/modules/
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Amit_Cleancache>
<active>true</active>
<codePool>community</codePool>
</Amit_Cleancache>
</modules>
</config>
In Magento > cache management > the 3 last cache options :
Additional Cache Management Flush Catalog Images Cache Pregenerated product images files. Flush Swatch Images Cache Pregenerated configurable swatches image files. Flush JavaScript/CSS Cache Themes JavaScript and CSS files combined to one file.
is it possible to flush these cache types using an auto cron job?
Reason being :
If I do not clear these caches regularly then the REDIS thing fails and everything crashes.
Thanks :)