You are here

private function DrupalFileCache::truncate_if_needed in File Cache 7

1 call to DrupalFileCache::truncate_if_needed()
DrupalFileCache::__construct in ./filecache.inc
Construct DrupalFileCache for specified cache bin.

File

./filecache.inc, line 148
DrupalFileCache class that implements DrupalCacheInterface.

Class

DrupalFileCache

Code

private function truncate_if_needed() {
  $registry_pathname = filecache_registry_pathname();
  $registry = @unserialize(@file_get_contents($registry_pathname));
  if (!isset($registry) || !is_array($registry)) {
    $registry = array();
  }
  $registry_changed = FALSE;
  $do_truncate = FALSE;
  if (!array_key_exists($this->bin, $registry)) {
    $registry[$this->bin] = NULL;
    $registry_changed = TRUE;
    $do_truncate = TRUE;
  }
  else {

    // Check all other cache bins in registry
    global $conf;
    foreach ($registry as $filecache_bin => $placeholder) {
      $cache_class_setting = 'cache_class_' . $filecache_bin;
      if (array_key_exists($cache_class_setting, $conf) && $conf[$cache_class_setting] != 'DrupalFileCache') {

        // The cache bin is configured for specified cache class but it is not our cache class.
        unset($registry[$filecache_bin]);
        $registry_changed = TRUE;
      }
    }
  }
  if ($registry_changed) {
    if ($this->ok && !filecache_is_readdeleteonly()) {
      file_put_contents($registry_pathname, serialize($registry));
    }
  }
  if ($do_truncate) {
    $db_cache = new DrupalDatabaseCache($this->bin);
    $db_cache
      ->clear('*', TRUE);
    $this
      ->delete_wildcard('');
  }
}