You are here

dynamic_cache.module in Dynamic Cache 6

Same filename and directory in other branches
  1. 7 dynamic_cache.module

Dynamic Cache module.

Allows other modules to disable page caching from hook_boot().

Usage: Set $GLOBALS['conf']['cache'] = CACHE_DISABLED in your own module's hook_boot(), as needed.

File

dynamic_cache.module
View source
<?php

/**
 * @file
 * Dynamic Cache module.
 *
 * Allows other modules to disable page caching from hook_boot().
 *
 * Usage: Set $GLOBALS['conf']['cache'] = CACHE_DISABLED in your own module's
 * hook_boot(), as needed.
 */

/**
 * Implements hook_boot().
 */
function dynamic_cache_boot() {
  if (dynamic_cache_should_run()) {

    // STEP 1: Complete remaining DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE steps from
    // _drupal_bootstrap() in includes/bootstrap.inc.
    // Prepare for non-cached page workflow.
    drupal_page_header();

    // STEP 2: Execute remaining bootstrap steps.
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

    // STEP 3: Complete remaining steps from index.php.
    // Execute page, get output.
    $return = menu_execute_active_handler();

    // Menu status constants are integers; page content is a string.
    if (is_int($return)) {
      switch ($return) {
        case MENU_NOT_FOUND:
          drupal_not_found();
          break;
        case MENU_ACCESS_DENIED:
          drupal_access_denied();
          break;
        case MENU_SITE_OFFLINE:
          drupal_site_offline();
          break;
      }
    }
    elseif (isset($return)) {

      // Print any value (including an empty string) except NULL or undefined:
      print theme('page', $return);
    }

    // Finish page output.
    drupal_page_footer();

    // We're done.
    exit;
  }
}

/**
 * Helper function that tests whether or not bootstrap should be hijacked.
 */
function dynamic_cache_should_run() {

  // 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;
  }

  // Hijack the bootstrap.
  if (array_key_exists('cache', $GLOBALS['conf']) && $GLOBALS['conf']['cache'] == CACHE_DISABLED) {
    return TRUE;
  }
  return FALSE;
}

Functions

Namesort descending Description
dynamic_cache_boot Implements hook_boot().
dynamic_cache_should_run Helper function that tests whether or not bootstrap should be hijacked.