Page 1 of 1

Quick/Easy way to clear cache

Posted: Sun Feb 22, 2009 7:23 pm
by woodp
When applying mods and styles, it's always a nuisance to get back into the ACP just to delete the cache. This short php script will do the same and much faster:

DelteForumCache.php

Code: Select all

<?PHP
// Deletes everything but index.htm and .htaccess from the phpBB cache directory

$cachedir = "cache";

    $dir = opendir($cachedir);

// Delete everything but index.htm and .htaccess

    while( $file = readdir( $dir ) ) {
       if ($file == "." or $file == ".." or $file == "index.htm" or $file == ".htaccess") {
          continue;
       }
       echo "Deleting $cachedir/$file ... ";
       if (unlink("$cachedir/$file")) {
          echo "Done.<BR>";
       } else {
          echo "Not done.<BR>";
       }
    }

// Do not remove subdirectory because we want two files to remain.
//
//    if (rmdir($cachedir)) {
//       echo "<BR>Directory $cachedir was completely deleted.<BR>";
//    } else {
//       echo "<BR>Directory $cachedir could not be completely deleted.  Check permissions.";
//    }
  
?>
Simply place this file in your /phpBB3 directory (same place as the config.php file) and call it from your browser with http://www.domain.com/phpBB3/DeleteForumCache.php

Voila! Cache cleared!

Re: Quick/Easy way to clear cache

Posted: Sun Feb 22, 2009 10:01 pm
by Daz
Hi,

It is until some lowlife(s) decide to use the script to slow down your forum/site :cry:

Daz

Re: Quick/Easy way to clear cache

Posted: Mon Feb 23, 2009 12:41 am
by woodp
Daz wrote:It is until some lowlife(s) decide to use the script to slow down your forum/site :cry:
Then remove the file when you're done updating the mod or style.

Frankly, my board has <100 users and <300 daily accesses. Cache has no impact on my board's response time. If there were an easy way to turn off cache altogether, I would do it in a heartbeat.

I'll repeat my claim - If you're debugging a mod or style, not having to log back and forth into ACP is a huge time saver!

Re: Quick/Easy way to clear cache

Posted: Mon Feb 23, 2009 12:59 am
by narqelion
An even easier way is to set ACP -> Load settings -> Recompile stale style components: to Yes. ;)

Re: Quick/Easy way to clear cache

Posted: Sat Jan 23, 2010 1:50 pm
by troublegum44
Woodp, I would like to thank you for this script.

I have experienced an issue where one of my cache files had corrupted, resulting in a white screen for the users.

Clearing out the cache using FTP did resolve this, but I thought it may be better if I could find a way to automatically clear the cache regularly to prevent this happening again, and resolve the issue if it does happen again and I am not around to clear the cache myself.

So I have uploaded your script and added a cronjob to my host's cPanel which runs the script once a day :D

To Daz who was concerned about people finding the file and running it, I did actually place the file in a non public directory so that other people can't access it, and changed the path to the cache directory in the $cachedir = "cache"; line.

It works a treat :)

Re: Quick/Easy way to clear cache

Posted: Sat Jan 23, 2010 8:24 pm
by Lumpy Burgertushie
why not fix the underlying problem instead of doing that?

robert

Re: Quick/Easy way to clear cache

Posted: Sun Jan 24, 2010 9:37 am
by troublegum44
Lumpy Burgertushie wrote:why not fix the underlying problem instead of doing that?

robert
The problem is that I am not sure what caused this as it has been working for months with no issues.

I suspect it was my caused by my host rebooting the server and a cache file was in the middle of writing at the time, as people did start reporting the problems not long after this.

Re: Quick/Easy way to clear cache

Posted: Fri May 14, 2010 3:48 pm
by 21846657
@woodp

Thanks for the handy script. Indeed a time saver :D

Re: Quick/Easy way to clear cache

Posted: Thu Aug 15, 2013 7:34 pm
by alexander7566
Thanks for this! I installed this on all my boards and created a script at my main site that I can call and it will clear the cache at all my sites at once, and very very fast too!

So thanks very much :mrgreen:

EDIT: Just realized this thread is 4 years old... Sorry!

Re: Quick/Easy way to clear cache

Posted: Sun Mar 08, 2015 4:50 pm
by Dakoom
It works! Great! Thank you!

Re: Quick/Easy way to clear cache

Posted: Sun Mar 08, 2015 8:01 pm
by Lumpy Burgertushie
there was no need for this at the time and certainly not now.

there was then and still is a purge cache button in the main page of the admin panel.
in 3.0 you sometimes had to refresh the style components separately as well. or, you could set the proper setting in the load settings page to do away with the need to refresh the style components.

with version 3.1 both of those options are still there.
you can purge the cache after each style edit, or you can set the "recompile stale style components" to yes in the load settings page and there will be no need to do anything but refresh your browser to see styling changes.


robert