Quick/Easy way to clear cache

For support and discussion related to templates, themes, and imagesets in phpBB 3.0.
Suggested Hosts
Locked
woodp
Registered User
Posts: 57
Joined: Tue Feb 17, 2004 6:27 am

Quick/Easy way to clear cache

Post by woodp » Sun Feb 22, 2009 7:23 pm

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!

User avatar
Daz
Registered User
Posts: 5236
Joined: Fri Dec 07, 2001 2:39 pm
Location: Yorkshire, UK

Re: Quick/Easy way to clear cache

Post by Daz » Sun Feb 22, 2009 10:01 pm

Hi,

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

Daz
Please and Thank You works wonders...
I reserve the right to post illogical (and totally wrong) replies.
...It's the subtle perfection in attention to detail that makes your work rock the way it does - cdkrg
Think simple - it's not necessarily what you draw that matters, it's what you perceive - Daz

Note: ForumImages<dot>com is no longer anything to do with me.

woodp
Registered User
Posts: 57
Joined: Tue Feb 17, 2004 6:27 am

Re: Quick/Easy way to clear cache

Post by woodp » Mon Feb 23, 2009 12:41 am

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!

narqelion
I've Been Banned!
Posts: 7235
Joined: Sat Dec 13, 2008 5:00 pm
Contact:

Re: Quick/Easy way to clear cache

Post by narqelion » Mon Feb 23, 2009 12:59 am

An even easier way is to set ACP -> Load settings -> Recompile stale style components: to Yes. ;)

troublegum44
Registered User
Posts: 58
Joined: Wed May 13, 2009 7:46 pm

Re: Quick/Easy way to clear cache

Post by troublegum44 » Sat Jan 23, 2010 1:50 pm

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 :)

User avatar
Lumpy Burgertushie
Registered User
Posts: 66751
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Quick/Easy way to clear cache

Post by Lumpy Burgertushie » Sat Jan 23, 2010 8:24 pm

why not fix the underlying problem instead of doing that?

robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

If a tree falls in the forest and nobody is there, does it make a sound?

troublegum44
Registered User
Posts: 58
Joined: Wed May 13, 2009 7:46 pm

Re: Quick/Easy way to clear cache

Post by troublegum44 » Sun Jan 24, 2010 9:37 am

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.

21846657
Registered User
Posts: 4
Joined: Fri May 14, 2010 2:26 pm

Re: Quick/Easy way to clear cache

Post by 21846657 » Fri May 14, 2010 3:48 pm

@woodp

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

alexander7566
Registered User
Posts: 171
Joined: Mon Mar 12, 2012 5:26 pm

Re: Quick/Easy way to clear cache

Post by alexander7566 » Thu Aug 15, 2013 7:34 pm

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!

User avatar
Dakoom
Registered User
Posts: 33
Joined: Sun Mar 08, 2015 12:24 pm

Re: Quick/Easy way to clear cache

Post by Dakoom » Sun Mar 08, 2015 4:50 pm

It works! Great! Thank you!
currently working on Klayz.com. phpBB at klayz.com/community/

User avatar
Lumpy Burgertushie
Registered User
Posts: 66751
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Quick/Easy way to clear cache

Post by Lumpy Burgertushie » Sun Mar 08, 2015 8:01 pm

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
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

If a tree falls in the forest and nobody is there, does it make a sound?

Locked

Return to “[3.0.x] Styles Support & Discussion”