You are here

function flush_page_cache_footer in Flush page cache 6

Implementation of hook_footer().

File

./flush_page_cache.module, line 117
Easing the pain when you need to flush...Drupal's cache.

Code

function flush_page_cache_footer() {
  if (!flush_page_cache_requested()) {
    return;
  }

  // Get full path and URL.
  $path = flush_page_cache_get_path();
  $url = flush_page_cache_get_url();

  // Ensure that the object cache was disabled.
  if (!flush_page_cache_test_object_cache_disabled()) {
    $message = "Failed to flush all cached objects for this page. Please read this 'Flush page cache' README.txt file for more information";
    drupal_set_message(t($message), 'error');
    watchdog('flush_page_cache', t($message), array(), WATCHDOG_ERROR);
  }
  else {

    // Display message about cached objects.
    drupal_set_message(t('Successfully flushed all cached objects for this page.'));
  }

  // Purge all possible page-level caches. Generally, only one page cache
  // mechanism should be enabled but just to be safe we will check all of them.
  // Varnish
  if (module_exists('varnish')) {
    varnish_expire_cache(array(
      $path,
    ));
    drupal_set_message(t('Successfully purged this cached page from Varnish.'));
  }

  // Drupal with support for Pressflow's CACHE_EXTERNAL.
  $is_cache_disabled = variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED ? TRUE : FALSE;
  $is_cache_external = defined('CACHE_EXTERNAL') && variable_get('cache', CACHE_DISABLED) == CACHE_EXTERNAL ? TRUE : FALSE;
  if (!$is_cache_disabled && !$is_cache_external) {
    cache_clear_all($url, 'cache_page');
    drupal_set_message(t('Successfully flushed this cached page from Drupal.'));
  }

  // Redirect to the URL.
  drupal_goto($url);
}