8

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.

  • 1
    set a cron job and clear cache – MeenakshiSundaram R Sep 24 '15 at 16:54
  • OK, basically I'm asking how to do that. How do I set a cronjob for this? – Tijdschriftenzo Sep 24 '15 at 16:58
  • have you set magento cron on your server? – Amit Bera Sep 24 '15 at 17:04
  • try Aoe_CacheCleaner – Akhilesh Patel Sep 24 '15 at 17:32
  • 1
    if you're refreshing cache at intervals, then i'd re-evaluate your implementation. – B00MER Sep 24 '15 at 17:34
14

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();
    }
}

Full module:

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>
  • The config.xml generates this error: "This page contains the following errors: error on line 14 at column 14: Opening and ending tag mismatch: models line 0 and global Below is a rendering of the page up to the first error. 1.0.0 Amit_Cleancache_Model" – Tijdschriftenzo Sep 25 '15 at 15:16
  • tag was not close..i have update the answer.. now check – Amit Bera Sep 25 '15 at 15:18
  • Great, works like a charm! – Tijdschriftenzo Sep 25 '15 at 15:25
  • @AmitBera How can i set cron job on my server, like every night autorefresh cache and reindex. – zus Feb 16 '18 at 6:19
  • @AmitBera I have created simple code for clear the cache. The code is : justpaste.it/6rjvd and cron configuration : snag.gy/AZowtf.jpg. Still cron not working, is right what i did? – Gem Jun 27 '18 at 4:48
-1

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.