You are here

function boost_expire_flush_boost_cache in Boost Expire 7

Function to clear Boost's cache.

At this time, this is a pretty stupid function, but that's because there are no easy ways to expire certain parts of the Boost cache, while Boost is still in development for Drupal 7. But it does it's job.

Clearing the entire Boost cache every time a comment is saved/updated, a node is saved/updated, etc. is definitely not ideal, but it's better than having to constantly hit the 'clear all caches' button or wait for cron expiration.

Parameters

$options: Associative array of options for this flush. Currently, only supported option is 'scope' => 'all'.

6 calls to boost_expire_flush_boost_cache()
boost_expire_comment_delete in ./boost_expire.module
Implements hook_comment_delete().
boost_expire_comment_insert in ./boost_expire.module
Implements hook_comment_insert().
boost_expire_comment_update in ./boost_expire.module
Implements hook_comment_update().
boost_expire_node_delete in ./boost_expire.module
Implements hook_node_delete().
boost_expire_node_insert in ./boost_expire.module
Implements hook_node_insert().

... See full list

File

./boost_expire.module, line 82
Expires Boost caches automatically when certain Drupal actions are taken.

Code

function boost_expire_flush_boost_cache($options = array()) {
  global $_boost, $base_path, $base_root;

  // If configured to respect the site's minimum cache lifetime, don't flush
  // cache until that much time has passed.
  if (variable_get('boost_expire_respect_minimum_cache_lifetime', 0)) {

    // Check if the minimum amount of time has passed.
    $lifetime = variable_get('cache_lifetime');
    $last_flush = variable_get('boost_expire_last_flush_time', 0);

    // If the last flush happened before the minimum lifetime has passed, exit.
    if ($last_flush > time() - $lifetime) {
      return;
    }
    else {
      variable_set('boost_expire_last_flush_time', time());
    }
  }

  // Borrow some logic from boost_htaccess_cache_dir_put() to build our base
  // directory path.
  if (empty($_boost['base_dir'])) {
    $url = $base_root . request_uri();
    $parts = parse_url($url);
    $_boost['base_dir'] = boost_get_normal_cache_dir() . '/' . $parts['host'] . $base_path;
  }

  // Borrow some logic from boost_flush_caches() to clear all the contents of
  // the boost directory for this site.
  if (!empty($options['scope']) && $options['scope'] == 'all') {
    if (isset($_boost['base_dir'])) {
      $count = _boost_rmdir($_boost['base_dir'], TRUE);
      $count = empty($count) ? 0 : $count;

      // Log the cache flush if configured.
      if (variable_get('boost_expire_log_flushes', 1)) {
        watchdog('boost_expire', 'Flushed all files (%count) from static page cache.', array(
          '%count' => $count,
        ), WATCHDOG_NOTICE);
      }
    }
  }
}