You are here

function dmemcache_stats_init in Memcache API and Integration 7

Same name and namespace in other branches
  1. 6 dmemcache.inc \dmemcache_stats_init()

Collect statistics if enabled.

Optimized function to determine whether or not we should be collecting statistics. Also starts a timer to track how long individual memcache operations take.

Return value

bool TRUE or FALSE if statistics should be collected.

6 calls to dmemcache_stats_init()
dmemcache_add in ./dmemcache.inc
Add an item into memcache.
dmemcache_delete in ./dmemcache.inc
Deletes an item from the cache.
dmemcache_flush in ./dmemcache.inc
Flush all stored items.
dmemcache_get in ./dmemcache.inc
Retrieve a value from the cache.
dmemcache_get_multi in ./dmemcache.inc
Retrieve multiple values from the cache.

... See full list

1 string reference to 'dmemcache_stats_init'
MemCacheStatisticsTestCase::testBootstrapStatistics in tests/memcache.test
Checks for early bootstrap statistics.

File

./dmemcache.inc, line 1226
A memcache API for Drupal.

Code

function dmemcache_stats_init() {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast =& drupal_static(__FUNCTION__, array(
      'variable_checked' => NULL,
      'user_access_checked' => NULL,
    ));
  }
  $variable_checked =& $drupal_static_fast['variable_checked'];
  $user_access_checked =& $drupal_static_fast['user_access_checked'];

  // Confirm DRUPAL_BOOTSTRAP_VARIABLES has been reached. We don't use
  // drupal_get_bootstrap_phase() as it's buggy. We can use variable_get() here
  // because _drupal_bootstrap_variables() includes module.inc immediately
  // after it calls variable_initialize().
  if (!isset($variable_checked) && function_exists('module_list')) {
    $variable_checked = variable_get('show_memcache_statistics', FALSE);
  }

  // If statistics are enabled we need to check user access.
  if (!empty($variable_checked) && !isset($user_access_checked) && !empty($GLOBALS['user']) && function_exists('user_access')) {

    // Statistics are enabled and the $user object has been populated, so check
    // that the user has access to view them.
    $user_access_checked = user_access('access memcache statistics');
  }

  // Return whether or not statistics are enabled and the user can access them.
  if ((!isset($variable_checked) || $variable_checked) && (!isset($user_access_checked) || $user_access_checked)) {
    timer_start('dmemcache');
    return TRUE;
  }
  else {
    return FALSE;
  }
}