You are here

function boost_cache_kill in Boost 6

Deletes cached page from file system.

Parameters

array $files: An array of files. Each file is a secondary array must have a key for 'filename' Optional keys for 'hash' and 'base_dir' that will be recalculated if necessary. The hash is the primary key in the database. If omitted it will be recalculated from the filename.

boolean $force_flush = FALSE: Override BOOST_EXPIRE_NO_FLUSH setting.

7 calls to boost_cache_kill()
boost_cache_expire_all_db in ./boost.module
Flushes all expired pages via database lookup.
boost_cache_expire_router in ./boost.module
Expires the static file cache for the given router items.
boost_cache_flush_by_filename in ./boost.module
Expires the static file cache for files given.
boost_cache_kill_url in ./boost.module
Deletes cached page from file system & database.
boost_crawler_run in ./boost.module
The brains of the crawler.

... See full list

File

./boost.module, line 3558
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function boost_cache_kill($files, $force_flush = FALSE) {
  $hashes = array();
  $count = 0;
  if (!$files) {
    return FALSE;
  }

  // If not ignoring file removal
  // AND site is multisite and cache path matches filename
  //  OR full base url matches filename
  if (variable_get('boost_ignore_flush', 0) < 3) {

    // Calc md5 hash and set base dir
    foreach ($files as $key => $file) {
      if (!is_string($file['filename'])) {
        if (BOOST_VERBOSE >= 5) {
          watchdog('boost', 'Error in boost_cache_kill() <br />String was not given for filename: !output', array(
            '!output' => boost_print_r($file, TRUE, TRUE),
          ));
        }
        continue;
      }
      if (empty($file['hash'])) {
        $files[$key]['hash'] = md5($file['filename']);
      }
      if (empty($file['base_dir'])) {
        $files[$key]['base_dir'] = BOOST_FILE_PATH;
      }
      $hashes[] = $files[$key]['hash'];
      if (stristr($files[$key]['filename'], BOOST_ROOT_CACHE_DIR) == FALSE) {
        unset($files[$key]);
      }
    }

    // Expire entries from Database
    if (count($hashes)) {
      if ($force_flush || !BOOST_EXPIRE_NO_FLUSH) {
        boost_db_multi_update_set('boost_cache', 'expire', '%d', 0, 'hash', "'%s'", $hashes);
        boost_db_multi_update_set('boost_cache', 'timer', '%d', 0, 'hash', "'%s'", $hashes);
      }
      else {
        boost_db_multi_update_set('boost_cache', 'expire', '%d', 434966400, 'hash', "'%s'", $hashes);
        $count = db_affected_rows();
      }
    }

    // Kill Files from filesystem
    if ($force_flush || !BOOST_EXPIRE_NO_FLUSH) {
      foreach ($files as $file) {
        $filenames = boost_get_all_filenames($file['filename'], $file['base_dir']);
        foreach ($filenames as $key => $values) {
          foreach ($values as $num => $filename) {
            if (file_exists($filename)) {
              @unlink($filename);
              if ($key == 'normal' && $num == 0) {
                $count++;
              }
            }
          }
        }
      }
    }
  }
  return $count;
}