Author Topic: Auto delete cache after cache lifetime is expired  (Read 3978 times)

0 Members and 1 Guest are viewing this topic.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Auto delete cache after cache lifetime is expired
« on: October 27, 2010, 09:00:39 AM »
I checked my cache directory and I found out that there are some very old cache files which have already been expired but till now none of the visitors has visit that page which cache belongs to.

That's why I'm wondering wouldn't be good if somehow cache is automatically deleted/removed when cache lifetime is expired?

I don't know how that would effect server load if every time someone refresh page cache directory is checked if there are expired files?
« Last Edit: October 27, 2010, 10:04:14 AM by Lucifix »

Offline x23piracy

  • Sr. Member
  • ****
  • Posts: 420
    • View Profile
    • FHG
Re: Auto delete cache after cache lifetime is expired
« Reply #1 on: October 27, 2010, 09:50:31 AM »
I checked my cache directory and I found out that there are some very old cache files which have already been expired but till now none of the visitors has visit that page which cache belongs to.

That's why I'm wondering wouldn't be good if somehow cache is automatically deleted/removed when cache lifetime is expired?

I don't know how that would effect server load if every time someone refresh page cache directory is checked if there are expired files?

Hi,

you can compare timestamp every time someone refreshes the page and only if the time between the
actual and the last timestamp is higher then X it checks for expired files and delete them...


Greetz X23

Don't trust in md5 it's unsafe change your 4i galerys password hash algorythm! second pw db field, create new hashes over some time, deny old hash. Help members that cry, send informationen mail to the rest. Camouflage new pw hash in cookie. Done!

--(◔̯◔)--

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Auto delete cache after cache lifetime is expired
« Reply #2 on: October 27, 2010, 09:56:43 AM »
I checked my cache directory and I found out that there are some very old cache files which have already been expired but till now none of the visitors has visit that page which cache belongs to.

That's why I'm wondering wouldn't be good if somehow cache is automatically deleted/removed when cache lifetime is expired?

I don't know how that would effect server load if every time someone refresh page cache directory is checked if there are expired files?

Hi,

you can compare timestamp every time someone refreshes the page and only if the time between the
actual and the last timestamp is higher then X it checks for expired files and delete them...


Greetz X23

This is what I have in mind, but I'm worried that this will only make higher server load.

I haven't tested this yet, but maybe this will do it:
Code: [Select]
function delete_cache_folder() {
  global $cache_enable, $cache_lifetime, $cache_path;

  $days = 1;
  $handle = opendir($cache_path);
  while ($file = @readdir($handle)) {
    if (is_dir($file) || $file{0} == ".") {
      continue;
    }
    if ((time() - filemtime($cache_path . '/' . $file)) & ($days * 86400)) {
unlink($cache_path . '/' . $file);
}
  }
}
Modified from:
http://www.danmyers.name/wp/2008/12/delete-files-older-than-xx-days-using-php/
« Last Edit: October 27, 2010, 11:17:19 AM by Lucifix »