Search code examples
cachingprestashopprestashop-1.6

Clear cache programmatically on Prestashop 1.6


One important module (payment) disappears from front office randomly.

I discover that if i clear cache from the back office (see image), the module is back again.

enter image description here

However, no cache is activated in BO but i need to click on the clear cache button.

So, for now, as i can’t find a solution, i decided to create a cron function to clear cache.

But my function seems to be incomplete because the module doesn’t show after calling this function. Again, if i clear cache from the BO (by clicking on the button "clear cache"), the module appears again.

Is something missing in my function ? I use Prestashop 1.6.1.6

Here is my code :

require(dirname(__FILE__) . '/config/config.inc.php');

// sécurité pour éviter qu'un robot ou un user appelle le script
$token = Tools::getValue('token');
if (!$token || $token != '169785') {
    die();
}

Tools::clearSmartyCache();
Tools::clearXMLCache();
Media::clearCache();
PrestaShopAutoload::getInstance()->generateIndex();

Solution

  • As the AdminPerformance controller do:

    Tools::clearSmartyCache();
    Tools::clearXMLCache();
    Media::clearCache();
    Tools::generateIndex();
    

    That's enough :)