Hi David,
Is there an automatic way to remove images from the cache when products are deleted from feed?
I realized not so good as some merchants don't update very frequently, or in the case of a couple small merchants, never. Not sure what to ask for.
Hi,
If you're using the default $imageCacheTime of 604800;
$imageCacheTime = 604800; // cache period in seconds, set to zero for proxy only mode
...which is 7 days, running a purge of cache files not updated in 30 days should keep the cache directly low as the script will only be deleting cached images that have _not_ been requested in the last 30 days. That is potentially a better resource usage scenario that holding on to images just because they are in the database but have not been requested in 30 days; let me know if you are still not sure of course...
Cheers,
David.
--
PriceTapestry.com
Yes, using default time. Doe this mean I don't need to use the script as cache is automatically updated every 7 days?
Hi,
It's not so much updated - but images will be _refreshed_ every 7 days, so that behaviour, in conjunction with running the purge script every 30 days will keep the cache/ folder size down to a minimum as once products have been deleted from a merchant feed, they will not be re-visited on the site, the cache file timestamp will not be updated, so imageCachePurge.php will delete the file after 30 days...
Cheers,
David.
--
PriceTapestry.com
Hi,
Here is a scripts/imageCachePurge.php script to remove image cache files that have not been refreshed in 30 days (adjust at line 6 as required)...
<?php
set_time_limit(0);
$cacheDir = "../cache/";
$days = 30;
$age = ($days * 86400);
$now = time();
$count = 0;
if ($dh = opendir($cacheDir))
{
while (($file = readdir($dh)) !== false)
{
$filename = $cacheDir.$file;
if (filemtime($filename) < ($now-$age))
{
unlink($filename);
$count++;
}
}
closedir($dh);
}
exit();
?>
This could be set-up to run, say weekly as a CRON job e.g.
cd /path/to/pricetapestry/scripts/;/usr/bin/php imageCachePurge.php
Hope this helps!
Cheers,
David.
--
PriceTapestry.com