You are here

function better_statistics_served_from_cache in Better Statistics 7

Determines whether or not the current request is being served from cache.

Note that you may need to use === to determine the cache status of the page, because some requests will return NULL, which evaluates to FALSE.

Parameters

boolean $recheck: (optional) If set to TRUE, cache status will be manually re-checked.

Return value

A boolean TRUE if the page is being served from cache, FALSE if the page is cacheable, but not served from cache. NULL is returned in the case when the page was never cacheable to begin with.

3 calls to better_statistics_served_from_cache()
better_statistics_better_statistics_prelog in ./better_statistics.statistics.inc
Implements hook_better_statistics_prelog().
better_statistics_exit in ./better_statistics.module
Implements hook_exit().
better_statistics_get_field_value in ./better_statistics.statistics.inc
Returns a value to be inserted into the accesslog based on a field name provided. This handles Drupal Core's values as well as our own.

File

./better_statistics.module, line 406
Drupal hook implementations for the Better Statistics module.

Code

function better_statistics_served_from_cache($recheck = FALSE) {
  static $cached;
  if (!isset($cached) || $recheck) {
    $headers = headers_list();
    $hit = array_search('X-Drupal-Cache: HIT', $headers);
    $miss = array_search('X-Drupal-Cache: MISS', $headers);

    // If neither a hit nor miss header are present, the page wasn't cacheable
    // to begin with. Return NULL.
    if ($hit !== FALSE) {
      $cached = TRUE;
    }
    elseif ($miss !== FALSE) {
      $cached = FALSE;
    }
    else {
      $cached = NULL;
    }
  }
  return $cached;
}