You are here

function filecache_cron in File Cache 7

Implements hook_cron().

See also

hook_cron()

File

./filecache.module, line 10

Code

function filecache_cron() {

  // Check if filecache is enabled in settings.php
  $filecache_enabled = FALSE;
  global $conf;
  foreach ($conf as $setting => $value) {
    if ($setting == 'cache_default_class' || substr($setting, 0, strlen('cache_class_')) === 'cache_class_') {
      if ($value === 'DrupalFileCache') {
        $filecache_enabled = TRUE;
        break;
      }
    }
  }

  // If filecache is disabled, be sure to remove filecache bin registry
  $filecache_registry_pathname = filecache_registry_pathname();
  if (!$filecache_enabled) {
    @unlink($filecache_registry_pathname);
    return;
  }

  // Load cache bin registry
  $registry = @unserialize(@file_get_contents($filecache_registry_pathname));
  if (!is_array($registry)) {
    @unlink($filecache_registry_pathname);
    return;
  }
  $cache_size = 0;
  foreach ($registry as $bin => $value) {
    $cache = new DrupalFileCache($bin);
    $cache_size += $cache
      ->delete_expired();
  }
  cache_set('filecache_space', array(
    'cache_size' => $cache_size,
  ));
}