Let's talk Contact us. No cost. No obligation.

Fill out this form and we will contact you with in 24 hrs.

    captcha

     

    Knowledge Base

    Refresh Invalidate cache via CRON job

    May 22, 2017

    Often, invalidate cache status is found in Magento, and in such scenario we need to keep on refreshing the cache status.

    To do this we can set a cron job that will check if cache in Invalid type, then it will refresh the cache.

    To do this we can follow bellow steps:

    Step1: We need to create “refresh-flush-cache.php” on root directory ”
    /var/www/html/ ”

    Below is file content.

    error_reporting(E_ALL ^ E_NOTICE);
    set_time_limit(0);
    ini_set(‘memory_limit’,’1024M’);
    ini_set(‘display_errors’,’1′);

    $rootDir = “/var/www/html/”;

    require_once($rootDir.”app/Mage.php”);
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    Mage::app(“default”);

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

    echo “Scripts Starts at=>”.date(“d/m/Y H:i:s”);

    foreach($types as $type)
    {
    echo “\n Cache Type=>”.$type->getId();
    Mage::app()->getCacheInstance()->cleanType($type->getId());
    }

    echo “\n Scripts Ends at=>”.date(“d/m/Y H:i:s”);
    ?>

    Step2: Now we have to set a cron for this file which will execute in every 30 min.