You are here

function authcache_exit in Authenticated User Page Caching (Authcache) 7.2

Same name and namespace in other branches
  1. 6 authcache.module \authcache_exit()
  2. 7 authcache.module \authcache_exit()

Implements hook_exit().

Called on drupal_goto() redirect. Make sure status messages show up, if applicable.

File

./authcache.module, line 139
Authenticated User Page Caching (and anonymous users, too!)

Code

function authcache_exit($destination = NULL) {
  global $user;

  // Do not continue if not fully bootstrapped.
  if (drupal_get_bootstrap_phase() < DRUPAL_BOOTSTRAP_FULL) {
    return;
  }

  // Cancel caching when hook_exit was called from drupal_goto.
  if ($destination !== NULL) {
    authcache_cancel(t('Redirecting to @destination', array(
      '@destination' => $destination,
    )));
  }

  // Disable authcache on next page request e.g., if there are messages pending
  // which did not manage it onto the current page.
  $reasons = module_invoke_all('authcache_preclude');
  if (!empty($reasons)) {
    _authcache_preclude(reset($reasons));
  }

  // Set/unset authcache key for this user.
  $authcache_key = authcache_key();
  if ($authcache_key !== authcache_backend_initial_key()) {
    $has_session = !empty($user->uid) || !empty($_SESSION);
    $lifetime = authcache_key_lifetime();
    module_invoke_all('authcache_backend_key_set', $authcache_key, $lifetime, $has_session);
  }

  // Fix cookies if necessary.
  if (!drupal_is_cli() && !headers_sent()) {
    authcache_fix_cookies();
  }

  // Forcibly disable drupal built-in page caching for anonymous users.
  // Prevent drupal_page_set_cache() called from drupal_page_footer() to
  // store the page.
  drupal_page_is_cacheable(FALSE);

  // If this page was excluded in hook_init, we're done here.
  if (authcache_excluded()) {
    return;
  }

  // Give other modules a last chance to cancel page saving.
  $reasons = module_invoke_all('authcache_cancel');
  if (!empty($reasons)) {
    authcache_cancel(reset($reasons));
  }

  // Invoke cache backends and serve page.
  if (authcache_page_is_cacheable()) {
    $cache = authcache_backend_cache_save();
    authcache_serve_page_from_cache($cache, authcache_key());
  }
}