Today I will show you how to programatically clear cache in PrestaShop. For example, you can make a CRON task which will execute this little PHP script once or more per day – depending on your needs.
1. Create PHP file in your store root (main) directory and name it as you wish – in this example it'll be cache_clear.php
2. Open this file and paste
include('./config/config.inc.php'); $token = Tools::getValue('token'); if($token == "vBnmmP3218") { Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); echo "Cache clear ended successfully."; } else { echo "Wrong security token - cache clear failed."; }
3. Change the string vBnmmP3218
to your random one (stronger is more secure).
4. Save the file.
5. Add script URL to your CRON task manager or execute it directly via your browser in format: http://{your_store_url}/cache_clear.php?token=vBnmmP3218
For example: http://example.com/cache_clear.php?token=vBnmmP3218