You are here

function dynamic_cache_should_run in Dynamic Cache 7

Same name and namespace in other branches
  1. 6 dynamic_cache.module \dynamic_cache_should_run()

Helper function that tests whether or not bootstrap should be hijacked.

1 call to dynamic_cache_should_run()
dynamic_cache_boot in ./dynamic_cache.module
Implements hook_boot().

File

./dynamic_cache.module, line 39
Dynamic Cache module.

Code

function dynamic_cache_should_run() {

  // If the CURRENT cache setting is TRUE there is no reason to hijack or to
  // do any of the other checks that follow.
  if ($GLOBALS['conf']['cache']) {
    return FALSE;
  }

  // Bootstrap called outside of normal index.php (e.g. cron.php).
  if (strpos($_SERVER['PHP_SELF'], 'index.php') === FALSE) {
    return FALSE;
  }

  // We are in a drush context.
  if (defined('DRUSH_BOOTSTRAP_DRUPAL_FULL')) {
    return FALSE;
  }

  // See if caching is enabled for this request independent of the current
  // "dynamic" state of the cache setting.
  $cache_enabled = FALSE;
  if (variable_get('page_cache_without_database')) {
    $cache_enabled = TRUE;
  }
  elseif (isset($GLOBALS['conf']['dynamic_cache_orig_cache'])) {
    $cache_enabled = $GLOBALS['conf']['dynamic_cache_orig_cache'];
  }

  // Now we need to be sure that this hook_boot is being called from
  // _drupal_bootstrap_page_cache(). If it's not then the conditions are not
  // in place for our hijack to work correctly (and the hijack is not even
  // needed as Drupal is not serving a cached page).
  if (isset($_COOKIE[session_name()]) || !$cache_enabled || !drupal_page_get_cache(TRUE)) {
    return FALSE;
  }

  // If we get to this point we are configured to dynamically override caching
  // and we know that it is safe to do so.
  return TRUE;
}