You are here

function flush_page_cache_page_alter in Flush page cache 7

Implements hook_page_alter().

File

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

Code

function flush_page_cache_page_alter(&$page) {
  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 page cache
  if (variable_get('cache', 0)) {
    cache_clear_all($url, 'cache_page');
    drupal_set_message(t('Successfully flushed this cached page from Drupal.'));
  }

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