close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Clear cache

Thread began 8/06/2014 2:35 pm by Bill | Last modified 8/06/2014 11:19 pm by Jamie | 832 views | 3 replies |

Bill

Clear cache

Is it possible to delete the cache for all Galleries instead of manually doing it?

I have just uploaded optimized images in every gallery and I now want to clear the cache for each gallery.

Sign in to reply to this post

Jamie

Hey Bill

I run a cron job every night on my sites to delete the image cache folder contents.

If it helps, here's the details

The script code is

<?php


define('PATH', 'images/image_cache/');

function destroy($dir) {
$mydir = opendir($dir);
while(false !== ($file = readdir($mydir))) {
if($file != "." && $file != "..") {
chmod($dir.$file, 0777);
if(is_dir($dir.$file)) {
chdir('.');
destroy($dir.$file.'/');
rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'all done.';


?>



Modify the line 'images/image_cache/' to point to the folder you wish to empty of content (it doesn't delete the folder just the contents)
If you want to empty multiple folders, just add more define('PATH', 'images/folder2/'); lines and adjust accordingly like this

<?php


define('PATH', 'images/folder1/');
define('PATH', 'images/folder2/');
define('PATH', 'images/folder3/');

function destroy($dir) {
$mydir = opendir($dir);
while(false !== ($file = readdir($mydir))) {
if($file != "." && $file != "..") {
chmod($dir.$file, 0777);
if(is_dir($dir.$file)) {
chdir('.');
destroy($dir.$file.'/');
rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'all done.';


?>



Just add that code script to a blank php file and save it - I name mine delete.php so I can tell quickly what it does!

Upload it to the root of your site

Go to your cpanel for the site and got to the cron section and add a cron job - I run this one once a day and typically set it to run in the wee hours. I set mine to run at 3:41 am (if you're on a shared server, other resources are typically being run by other sites in the hour or half hour so this reduces your cron job from not running)

The path you need to run the cron will depend on your host but this is one of mine so you can see the structure

/usr/bin/php /home/ybgorrvn/public_html/delete.php

Hope that this helps...if you have any questions do get in touch

All the best

Jamie

Sign in to reply to this post

Bill

Originally Said By: Jamie
  I run a cron job every night on my sites to delete the image cache folder contents.  



Hi Jamie, Thanks for your detailed reply.

I would like to ask what the benefit is of deleting the cache every night?

Sign in to reply to this post

Jamie

I noticed a couple of years ago that the image cache folders on a couple of sites just became bloated as images were added and removed over time as the older cached images remain. This was in the main caused because I had a gallery used on every page of the site (not a large site though) which caused image cache to be created per page

This caused me large problems on one site in particular when the inode limit was smashed (the .txt file of the inode structure alone was a massive 50mb)

Also on that site as well the disk size was constantly hitting its limit (which obviously caused other issues as a result) and the only way to stop this from happening and managing was to run the script every night.... On that particular site I went from having to micro manage it every couple of days to empty the image_cache folder to not having to touch it at all

That works for me and am happy to flush the image_cache folder every night (it doesn't hurt to do this and I find it can help the user experience as they will rarely see an old cached version - it should always be the current image version) but you can set it to whatever interval you wish.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...