You are here

function memcache_stampede_protected in Memcache API and Integration 6

Determines whether stampede protection is enabled for a given bin/cid.

Memcache stampede protection is primarily designed to benefit the following caching pattern: a miss on a cache_get for a specific cid is immediately followed by a cache_set for that cid. In cases where this pattern is not followed, stampede protection can be disabled to avoid long hanging locks. For example, a cache miss in Drupal core's module_implements() won't execute a cache_set until drupal_page_footer() calls module_implements_write_cache() which can occur much later in page generation.

Parameters

string $cid: The cache id of the data to retrieve.

string $bin: The bin the data is stored in.

Return value

bool Returns TRUE if stampede protection is enabled for that particular cache bin/cid, otherwise FALSE.

1 call to memcache_stampede_protected()
cache_get in ./memcache.inc
Return data from the persistent cache.

File

./memcache.inc, line 517

Code

function memcache_stampede_protected($cid, $bin) {
  $ignore_settings = variable_get('memcache_stampede_protection_ignore', array(
    // Disable stampede protection for specific cids in 'cache_bootstrap'.
    'cache' => array(
      // Variables have their own lock protection.
      'variables',
      // I18n uses a class destructor to write the cache.
      'i18n:string:*',
    ),
  ));

  // Support ignoring an entire bin.
  if (in_array($bin, $ignore_settings)) {
    return FALSE;
  }

  // Support ignoring by cids.
  if (isset($ignore_settings[$bin])) {

    // Support ignoring specific cids.
    if (in_array($cid, $ignore_settings[$bin])) {
      return FALSE;
    }

    // Support ignoring cids starting with a suffix.
    foreach ($ignore_settings[$bin] as $ignore) {
      $split = explode('*', $ignore);
      if (count($split) > 1 && strpos($cid, $split[0]) === 0) {
        return FALSE;
      }
    }
  }
  return TRUE;
}