The lifetime is handled on the php side. For http caching, if there are not any directives that will handle this for your http server, you would have to run a cron. I would recommend an actual cron job and not wp cron. Somthing like this would do the trick:
$cacheDir = '/your-document-root/gator_cache'; // gator cache directory
$time = time();
$ttl = 14400; // 4 hours
$directory = new RecursiveDirectoryIterator($cacheDir);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
$cacheFiles = new RegexIterator($iterator, '~index\.(html|gz)$~');
foreach ($cacheFiles as $file) {
$path = $file->getPathName();
if (($time - filemtime($path)) > $ttl) {
printf("Removing cache file %s\n", $path);
unlink($path);
}
}
In the next update, will probably have the http tab generate this script with the appropriate ttl and cache dirs populated for better http caching.
Thread Starter
ram108
(@ram108)
Thank you very much! I will try your script.
Why not to add a job to wp-cron?
We need an example of nginx settings to work with cache files directly also. It is only apache .htaccess example right now.
I took “W3 Total Cache Rules” from here and they work.