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.
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.
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
Hi Jamie, Thanks for your detailed reply.
I would like to ask what the benefit is of deleting the cache every night?
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.
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
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.