You are here

function dmemcache_static in Memcache API and Integration 6

Provides central static variable storage.

Backported from Drupal 7 bootstrap.inc (renamed from drupal_static) to minimize changes when backporting patches from the memcache-7.x-1.x.

Parameters

$name: Globally unique name for the variable. For a function with only one static, variable, the function name (e.g. via the PHP magic __FUNCTION__ constant) is recommended. For a function with multiple static variables add a distinguishing suffix to the function name for each one.

$default_value: Optional default value.

$reset: TRUE to reset one or all variables(s). This parameter is only used internally and should not be passed in; use drupal_static_reset() instead. (This function's return value should not be used when TRUE is passed in.)

Return value

Returns a variable by reference.

See also

drupal_static_reset()

8 calls to dmemcache_static()
dmemcache_delete in ./dmemcache.inc
Deletes an item from the cache.
dmemcache_piece_cache_get in ./dmemcache.inc
Determine if a key has multi-piece values.
dmemcache_piece_cache_set in ./dmemcache.inc
Track active keys with multi-piece values, necessary for efficient cleanup.
dmemcache_set in ./dmemcache.inc
Place an item into memcache
dmemcache_static_reset in ./dmemcache.inc
Resets one or all centrally stored static variable(s).

... See full list

File

./dmemcache.inc, line 967

Code

function &dmemcache_static($name, $default_value = NULL, $reset = FALSE) {
  static $data = array(), $default = array();

  // First check if dealing with a previously defined static variable.
  if (isset($data[$name]) || array_key_exists($name, $data)) {

    // Non-NULL $name and both $data[$name] and $default[$name] statics exist.
    if ($reset) {

      // Reset pre-existing static variable to its default value.
      $data[$name] = $default[$name];
    }
    return $data[$name];
  }

  // Neither $data[$name] nor $default[$name] static variables exist.
  if (isset($name)) {
    if ($reset) {

      // Reset was called before a default is set and yet a variable must be
      // returned.
      return $data;
    }

    // First call with new non-NULL $name. Initialize a new static variable.
    $default[$name] = $data[$name] = $default_value;
    return $data[$name];
  }

  // Reset all: ($name == NULL). This needs to be done one at a time so that
  // references returned by earlier invocations of dmemcache_static() also get
  // reset.
  foreach ($default as $name => $value) {
    $data[$name] = $value;
  }

  // As the function returns a reference, the return should always be a
  // variable.
  return $data;
}