RinosN Posted April 30, 2015 Share Posted April 30, 2015 My site runs automatic daily cron tasks that activate/deactivate some product values, as "On sale", directly on the database tables. I've noticed that some modules, for example homefeatured or new products in home page don't reflect those changes if I don't clear the cache. I know I can clear the cache manually from Backoffice (not a practical solution), or as some topics show, I can resolve it with a cron task using: Tools::clearSmartyCache(); That works fine when you need to clear the whole site cache, but as I only need to clear the cache for those 2 specific templates: Home featured & Home new products, clearing all the cache seems unnecesary. How can I use the Tools::clearSmartyCache(); to clear just some specific templates? I can't find any documentation regarding this. Based on an older topic I've tried: // clear only cache for index.tpl$smarty->clear_cache('homefeatured.tpl'); --> Does nothing on my Prestashop 1.6.0.9 & Tools::clearSmartyCache('homefeatured.tpl'); ---> Clears all the cache not just the template. Any help will be appreciated. Thanks Link to comment Share on other sites More sharing options...
Krystian Podemski Posted April 30, 2015 Share Posted April 30, 2015 Check _clearCache method from Module.php file and you'll see how it works Link to comment Share on other sites More sharing options...
RinosN Posted April 30, 2015 Author Share Posted April 30, 2015 Hi, I've checked the _clearCache method on Module.php /*************/ protected function _clearCache($template, $cache_id = null, $compile_id = null) { Tools::enableCache(); if ($cache_id === null) $cache_id = $this->name; $number_of_template_cleared = Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath($template), $cache_id, $compile_id); Tools::restoreCacheSettings(); return $number_of_template_cleared; } /*************/ But I can no imagine how to translate this to a php cron task. I was expecting something more simple like the way with: Tools::clearSmartyCache(); Thanks for your recommendation. Link to comment Share on other sites More sharing options...
RinosN Posted April 30, 2015 Author Share Posted April 30, 2015 Based on Krystian's suggestion, finally I've managed to create this script as a cron task in my root folder: //////////////////////////////// require(dirname(__FILE__).'/config/config.inc.php'); if (!Tools::enableCache()) echo "enable Cache failed"; // To control if ends ok if (!Tools::clearCache(Context::getContext()->smarty, getTemplatePath('blocknewproducts_home.tpl'), null, null)) echo "clearCache failed"; // To control if ends ok if (!Tools::restoreCacheSettings()) echo "restoreCache failed"; // To control if ends ok////////////////////// When executed no changes are made to the blocknewproducts_home results and I receive the: "enableCache failed" custom control warning message. Any ideas what's going wrong? Thanks Link to comment Share on other sites More sharing options...
rayrodriguezg Posted January 9, 2019 Share Posted January 9, 2019 https://www.smarty.net/docs/en/api.clear.compiled.tpl.tpl $this->context->smarty->clearCompiledTemplate('blockbestsellers.tpl'); for example... this command delete from /cache/compile folder... Link to comment Share on other sites More sharing options...
remifr Posted May 21 Share Posted May 21 have you found a working solution for your CRON ? I have the exact same issue. Clearing the whole cache makes my website returning 500 error for 20 seconds when I only need to flush those 2 home modules.. 😕 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now