intershop Posted July 10, 2014 Share Posted July 10, 2014 i have a site of 4 giga . i have a hosting of 10 giga . my cache of prestashop if i forget to clear after 10 days is 11 giga so i have problems with the hosting company . if i clear smarty cache and autoload cache then it goes again to 4 giga . CAN I do this automaticaly for example every day or every week ? Link to comment Share on other sites More sharing options...
bellini13 Posted July 12, 2014 Share Posted July 12, 2014 (edited) What I would do is create a php script that would execute the clear cache functions, the same as would be done when you click "clear cache" in the back office. The script should work assuming you place the script in the root folder of your store <?php require(dirname(__FILE__).'/config/config.inc.php'); //change 'abc123' to any value you wish to use $token = Tools::getValue('token'); if (!$token || $token != 'abc123') die(); Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); PrestaShopAutoload::getInstance()->generateIndex(); Then create a new cronjob that would execute your php script at the interval you desire, and you can test this from a browser to ensure it works properly http://www.yourdomain.com/yourscript.php?token=abc123 Edit 5/16: Updated script to include a token Edited May 17, 2015 by bellini13 (see edit history) 5 Link to comment Share on other sites More sharing options...
eduardorq Posted August 29, 2014 Share Posted August 29, 2014 Thanks bellini13... it works.! 1 Link to comment Share on other sites More sharing options...
bellini13 Posted August 29, 2014 Share Posted August 29, 2014 i would suggest securing this file so that bots and other users do not stumble onto it and start clearing your cache randomly on you Link to comment Share on other sites More sharing options...
lateral Posted October 17, 2014 Share Posted October 17, 2014 (edited) How do you "secure" it? Also, when I run it how do I know for sure it's actually working and clearing the cache? Edited October 17, 2014 by lateral (see edit history) Link to comment Share on other sites More sharing options...
uvip Posted October 17, 2014 Share Posted October 17, 2014 What version are you using there? We do not have the cache problem here. Link to comment Share on other sites More sharing options...
lateral Posted October 17, 2014 Share Posted October 17, 2014 I don't understand your question...are you asking me what version of Prestashop I'm using...1.6.0.9. I have needed to Clear the cache on a number of occasions to resolve issues and I though that I would set up an automatic Cron Job task to run a Clear Cache on a regular basis... Link to comment Share on other sites More sharing options...
fabiosat Posted December 13, 2014 Share Posted December 13, 2014 Thanks bellini13 !!!!! Link to comment Share on other sites More sharing options...
jjryeste Posted April 20, 2015 Share Posted April 20, 2015 Ok thank you work good is possible detele also , class_index.php in root/cache thank you Link to comment Share on other sites More sharing options...
kapra Posted May 15, 2015 Share Posted May 15, 2015 to clear cache...advance parameters---performance...top right corner....clear cache. Link to comment Share on other sites More sharing options...
lateral Posted May 15, 2015 Share Posted May 15, 2015 Hi Bellini13 I created the PHP file and executed it from the browser to test it but it seems to run very quickly compared to when I manually clear the cache from the back office. For example, from the browser it takes 1-2 seconds, from the back office it always takes 14-15 seconds. Do I need to also create a security key and use that from the browser??? How can I visually confirm if the cache has been cleared? Is there a set of files I can "see" if they have bee deleted? Thanks Regards Greg Link to comment Share on other sites More sharing options...
bellini13 Posted May 15, 2015 Share Posted May 15, 2015 to clear cache...advance parameters---performance...top right corner....clear cache. reading is fundamental... they asked if they can run a script to automate the process. I guess if you are Homer Simpson, you could use a pencil attached to a lever to click a button every 24 hours... for the rest of us, we create scripts and run them via cron so we can walk away from the computer 1 2 Link to comment Share on other sites More sharing options...
bellini13 Posted May 15, 2015 Share Posted May 15, 2015 Do I need to also create a security key and use that from the browser??? No, but its not a bad idea How can I visually confirm if the cache has been cleared? Is there a set of files I can "see" if they have bee deleted? yes, under /cache/smarty/cache and /cache/smarty/compile The sub files and folders should be removed 1 Link to comment Share on other sites More sharing options...
lateral Posted May 15, 2015 Share Posted May 15, 2015 (edited) Hi Bellini13, It's working! I ran some tests and looked a the folders under the cache folder and they are being deleted! What is the best and easiest way to secure the file? Thanks again. Also, regarding the use of a security key, are you saying that I don't really need to use a key because I'm not accessing the database? Regards Greg Edited May 15, 2015 by lateral (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted May 17, 2015 Share Posted May 17, 2015 The only thing the script is doing is clearing the cache on the file system. The only reason to secure the file is to prevent a bot from indexing it and clearing the cache on you, or from someone stumbling onto it and clearing your cache. Using a token would help prevent those things from happening if they do not know what the token value is. I've updated the original post to add that logic Link to comment Share on other sites More sharing options...
lateral Posted May 17, 2015 Share Posted May 17, 2015 You're a legend? Is this the correct format? http://mydomain.com/clearcache.php?secure_key=1234567890ASDFG Regards Greg Link to comment Share on other sites More sharing options...
lateral Posted May 17, 2015 Share Posted May 17, 2015 (edited) Hi Bellini13 Can you please do me a really big favour and look a this other post of mine regarding running an Update query from a script that is run as a Cron task? https://www.prestashop.com/forums/topic/441190-run-database-mysql-update-query-from-prestashop-cron-task-or-sql-function-in-backend/?do=findComment&comment=2049896 I feel I'm almost there but need an expert to tell me what's wrong... Thanks Regards Greg Edited May 17, 2015 by lateral (see edit history) Link to comment Share on other sites More sharing options...
ietax Posted October 8, 2015 Share Posted October 8, 2015 Hi, I'd like to use script. How can I use token function? If i set $token != 'abc123' where i should use it? thanks Link to comment Share on other sites More sharing options...
SirBob Posted December 20, 2015 Share Posted December 20, 2015 Hi Very useful thread! Thanks Bellini13 for the script! Will it work with PS v 1.6.1.3 as well? Thank you. Link to comment Share on other sites More sharing options...
prestandrew Posted March 3, 2016 Share Posted March 3, 2016 Not working on 1.6.0.14. Link to comment Share on other sites More sharing options...
natebc Posted May 3, 2016 Share Posted May 3, 2016 What I would do is create a php script that would execute the clear cache functions, the same as would be done when you click "clear cache" in the back office. The script should work assuming you place the script in the root folder of your store <?php require(dirname(__FILE__).'/config/config.inc.php'); //change 'abc123' to any value you wish to use $token = Tools::getValue('token'); if (!$token || $token != 'abc123') die(); Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); PrestaShopAutoload::getInstance()->generateIndex(); Then create a new cronjob that would execute your php script at the interval you desire, and you can test this from a browser to ensure it works properly http://www.yourdomain.com/yourscript.php?token=abc123 Edit 5/16: Updated script to include a token Hi bellini13, Thanks for the script. I have upload the php file and setup the cronjob, that look to be ruining fine. But cache seems not to be clearing/deleting. Natebc Link to comment Share on other sites More sharing options...
natebc Posted May 9, 2016 Share Posted May 9, 2016 Hello, has any one had issue with is script? We have been told by our website hosting company says that is dose not work. We are in need of this in a big way. We have 2-4 GB upload every day. If any one can help up please let us know. Natebc Link to comment Share on other sites More sharing options...
bellini13 Posted May 9, 2016 Share Posted May 9, 2016 Hello, has any one had issue with is script? We have been told by our website hosting company says that is dose not work. We are in need of this in a big way. We have 2-4 GB upload every day. If any one can help up please let us know. Natebc what version of Prestashop are you using? what exactly 'does not work' Link to comment Share on other sites More sharing options...
natebc Posted May 9, 2016 Share Posted May 9, 2016 what version of Prestashop are you using? what exactly 'does not work' Hi Bellini13, We are using 1.6.1.1. We use Total import pro to automatically update 15-16k products twice a day. This leaves 4-5GB in cache. We have copy and past the script and place that file in to root folder. Then set up a cron job. But it will not empty any cache in the folders. Natebc Link to comment Share on other sites More sharing options...
bellini13 Posted May 9, 2016 Share Posted May 9, 2016 As the original post states, this functions exactly like clicking the "clear cache" button in the back office performance page. It clears Smarty Cache XML Cache Media Cache So the questions is... when you click the "Clear cache" button in your back office, does this "cache" you refer to also get cleared? My guess is that the answer is no. Link to comment Share on other sites More sharing options...
rameshuv Posted June 11, 2016 Share Posted June 11, 2016 (edited) Hello Bellini I'm also facing same problem - prestashop version 1.6.1.4 i've created the file task.php and save it in to the root folder <?phprequire(dirname(__FILE__).'/config/config.inc.php');$token = Tools::getValue('token');if (!$token || $token != 'crontask') die();Tools::clearSmartyCache();Tools::clearXMLCache();Media::clearCache();PrestaShopAutoload::getInstance()->generateIndex(); and tested my site following url format https://www.test.com/task.php not working when i click the "Clear cache" button in back office it's working Regards Ramesh Edited June 11, 2016 by rameshuv (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted June 13, 2016 Share Posted June 13, 2016 @Ramesh: You did not pass a token in the URL. go back through the replies Link to comment Share on other sites More sharing options...
rameshuv Posted June 16, 2016 Share Posted June 16, 2016 @Ramesh: You did not pass a token in the URL. go back through the replies Thanks for your quick reply here it goes https://www.test.com/index.php?token=crontask not working please advise Regards Ramesh Link to comment Share on other sites More sharing options...
bellini13 Posted June 17, 2016 Share Posted June 17, 2016 did you update the script to check for your token value 'crontask' what exactly does 'not working' mean? Link to comment Share on other sites More sharing options...
rameshuv Posted June 17, 2016 Share Posted June 17, 2016 (edited) did you update the script to check for your token value 'crontask' what exactly does 'not working' mean? Yes i updated as mentioned below <?php require(dirname(__FILE__).'/config/config.inc.php'); $token = Tools::getValue('token'); if (!$token || $token != 'crontask') die(); Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); PrestaShopAutoload::getInstance()->generateIndex(); It's not deleting clear smarty cache files automatically with this script. I can do it manually from back office "Clear cache" button its perfectly working. Regards Ramesh Edited June 17, 2016 by rameshuv (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted June 17, 2016 Share Posted June 17, 2016 ok Link to comment Share on other sites More sharing options...
Totti Posted June 18, 2016 Share Posted June 18, 2016 What makes this class ? PrestaShopAutoload::getInstance()->generateIndex(); Link to comment Share on other sites More sharing options...
Aloud Posted July 5, 2016 Share Posted July 5, 2016 Could anyone help a dummy and provide the full php file and where to put it in the root? I created a file with the code provided as clear_cache.php and created the cron job for it but it aint working Link to comment Share on other sites More sharing options...
tarek.fellah Posted February 8, 2017 Share Posted February 8, 2017 (edited) No, but its not a bad idea yes, under /cache/smarty/cache and /cache/smarty/compile The sub files and folders should be removed Hi, I have presta 1.6.1.10, i tried to clear cache by code, but modules folders in cache/smarty/cache are not removed, You know why? Thanks. Edited February 8, 2017 by tarek.fellah (see edit history) Link to comment Share on other sites More sharing options...
perarg Posted July 7, 2017 Share Posted July 7, 2017 Hello, i need to make a cron job to clean the cache. In this thread there is a script from 2014. We are in 2017 and the prestashop version is about 1.6.1.x Is this script still valid ? I want to try it and post here the results but how can i be sure that the script gets the work done ? Link to comment Share on other sites More sharing options...
mmsh Posted October 5, 2017 Share Posted October 5, 2017 (edited) Hello, i need to make a cron job to clean the cache. In this thread there is a script from 2014. We are in 2017 and the prestashop version is about 1.6.1.x Is this script still valid ? I want to try it and post here the results but how can i be sure that the script gets the work done ? <?php require(dirname(__FILE__).'/config/config.inc.php'); //change 'abc123' to any value you wish to use $token = Tools::getValue('token'); if (!$token || $token != 'abc123') { echo "Wrong token"; die(); } Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); echo "Cache cleared"; ?> this works, but you need to keep attention. It seems it doesn't work if you have cache on /tmp mounted on tmpfs and PrivateTmp on systemd config for php-fpm is set to true... so, or you keep the tmp on disk or you need to set PrivateTmp to false on /usr/lib/systemd/system/php-fpm.service (here on CentOS 7) and then reload the systemd daemon and restart php-fpm. So, tmp must be set as usual and not on systemd-private-***/tmp/... that's all Edited October 5, 2017 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
andr3net0 Posted November 13, 2018 Share Posted November 13, 2018 Hello! I've added a new Category but is not shown, if i go to Advanced>Performance>Clear Cache when the page is reloaded the new category appears. I need to clear the cache by code. I am currently executing this code: <?php ini_set('memory_limit', '1024M'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require('/home/h32w38t0/wear.mixndream.com/config/config.inc.php'); Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); echo "Cache cleared"; ?> I had to remove the code below because it would say "Wrong token", $token is empty. $token = Tools::getValue('token'); if (!$token || $token != 'abc123') { echo "Wrong token"; die(); } My version is 1.7.4.2. Can you help me? Thanks! Link to comment Share on other sites More sharing options...
MaXi32 Posted June 30, 2020 Share Posted June 30, 2020 I know this is an old thread, but is the clear cache equivalence to removing /var/cache folder? If this is correct then, we can just setup a script to remove /var/cache folder at specific time. No need to make the script as it's not best security practice to send argument to execute php script Link to comment Share on other sites More sharing options...
MaXi32 Posted June 30, 2020 Share Posted June 30, 2020 After gone through some testing, I found out that in the latest prestashop 1.7, when you clear cache, the only cache folders that is being used is in /var/cache/* There are 2 folders inside that /var/cache/ called Prod and Dev, If you enable debug mode, the cache folder will go inside /var/cache/dev and if you disable debug, it will go into /var/cache/prod. Also it has been mentioned that prestashop 1.7 doesn't use /cache/* folders: here So, with this information, the solution to delete prestashop cache in prestashop 1.7 manually is to write a script to delete all files inside /var/cache/* and this script can run X time. Search about prestashop cronjob (maybe they have ready module) + how to delete folder in php script. Link to comment Share on other sites More sharing options...
solsol69 Posted July 4, 2020 Share Posted July 4, 2020 Le 30/06/2020 à 7:28 PM, arafatx a dit : Search about prestashop cronjob (maybe they have ready module) + how to delete folder in php script. hi I haven't tested it 1 Link to comment Share on other sites More sharing options...
Prestafan33 Posted July 4, 2020 Share Posted July 4, 2020 (edited) 6 hours ago, solsol69 said: hi I haven't tested it Yes, you can use this module. The method it uses to clear cache is the same that @mmsh describes in his post in this thread. It has two execution methods available: through own module (you can set execution time at settings), or through a CRON task (you'll get an URL you can use to program it at CRON job). I posted the module in Spanish forum, but it's also in english, so you can use it and settings will appear in english. Edited July 4, 2020 by Prestafan33 (see edit history) Link to comment Share on other sites More sharing options...
MaXi32 Posted July 13, 2020 Share Posted July 13, 2020 On 7/5/2020 at 3:12 AM, Prestafan33 said: Yes, you can use this module. The method it uses to clear cache is the same that @mmsh describes in his post in this thread. It has two execution methods available: through own module (you can set execution time at settings), or through a CRON task (you'll get an URL you can use to program it at CRON job). I posted the module in Spanish forum, but it's also in english, so you can use it and settings will appear in english. Since you are the developer of this module, I have a question: Does deleting the /var/cache folder manually equivalent to cleaning everything using this module ? Link to comment Share on other sites More sharing options...
Prestafan33 Posted July 13, 2020 Share Posted July 13, 2020 (edited) It should be the same, but it also deletes XML cache and theme cache. This module only makes the same you were talking about in this thread, cleaning cache using this: Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); It also adds the ability to set a time for cleaning repeatedly. But the way it works is the same as other people were posting here. You can check at Tools.php and Media.php files the content of those methods: /** * Clear Smarty cache and compile folders. */ public static function clearSmartyCache() { $smarty = Context::getContext()->smarty; Tools::clearCache($smarty); Tools::clearCompile($smarty); } /** * Clear XML cache folder. */ public static function clearXMLCache() { foreach (scandir(_PS_ROOT_DIR_ . '/config/xml', SCANDIR_SORT_NONE) as $file) { $path_info = pathinfo($file, PATHINFO_EXTENSION); if (($path_info == 'xml') && ($file != 'default.xml')) { self::deleteFile(_PS_ROOT_DIR_ . '/config/xml/' . $file); } } } /** * Clear theme cache. */ public static function clearCache() { $files = array_merge( glob(_PS_THEME_DIR_ . 'assets/cache/*', GLOB_NOSORT), glob(_PS_THEME_DIR_ . 'cache/*', GLOB_NOSORT) ); foreach ($files as $file) { if ('index.php' !== basename($file)) { Tools::deleteFile($file); } } $version = (int) Configuration::get('PS_CCCJS_VERSION'); Configuration::updateValue('PS_CCCJS_VERSION', ++$version); $version = (int) Configuration::get('PS_CCCCSS_VERSION'); Configuration::updateValue('PS_CCCCSS_VERSION', ++$version); } Edited July 13, 2020 by Prestafan33 (see edit history) Link to comment Share on other sites More sharing options...
MaXi32 Posted July 14, 2020 Share Posted July 14, 2020 (edited) 22 hours ago, Prestafan33 said: It should be the same, but it also deletes XML cache and theme cache. This module only makes the same you were talking about in this thread, cleaning cache using this: Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); It also adds the ability to set a time for cleaning repeatedly. But the way it works is the same as other people were posting here. You can check at Tools.php and Media.php files the content of those methods: /** * Clear Smarty cache and compile folders. */ public static function clearSmartyCache() { $smarty = Context::getContext()->smarty; Tools::clearCache($smarty); Tools::clearCompile($smarty); } /** * Clear XML cache folder. */ public static function clearXMLCache() { foreach (scandir(_PS_ROOT_DIR_ . '/config/xml', SCANDIR_SORT_NONE) as $file) { $path_info = pathinfo($file, PATHINFO_EXTENSION); if (($path_info == 'xml') && ($file != 'default.xml')) { self::deleteFile(_PS_ROOT_DIR_ . '/config/xml/' . $file); } } } /** * Clear theme cache. */ public static function clearCache() { $files = array_merge( glob(_PS_THEME_DIR_ . 'assets/cache/*', GLOB_NOSORT), glob(_PS_THEME_DIR_ . 'cache/*', GLOB_NOSORT) ); foreach ($files as $file) { if ('index.php' !== basename($file)) { Tools::deleteFile($file); } } $version = (int) Configuration::get('PS_CCCJS_VERSION'); Configuration::updateValue('PS_CCCJS_VERSION', ++$version); $version = (int) Configuration::get('PS_CCCCSS_VERSION'); Configuration::updateValue('PS_CCCCSS_VERSION', ++$version); } Thanks a lot for this information. I thought that in prestashop 1.7, the theme cache also went inside /var/cache folder. Now I understand. Edited July 14, 2020 by arafatx (see edit history) Link to comment Share on other sites More sharing options...
raunhar Posted April 1, 2021 Share Posted April 1, 2021 I am using Presta 1.7.6 How can I use this script. Do I make any modifications to it . 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