You are here

function dmemcache_get in Memcache API and Integration 7

Same name and namespace in other branches
  1. 5.2 dmemcache.inc \dmemcache_get()
  2. 5 dmemcache.inc \dmemcache_get()
  3. 6 dmemcache.inc \dmemcache_get()

Retrieve a value from the cache.

Parameters

string $key: The key with which the item was stored.

string $bin: The bin in which the item was stored.

Return value

mixed The item which was originally saved or FALSE

10 calls to dmemcache_get()
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.
lock_acquire in ./memcache-lock-code.inc
Acquire (or renew) a lock, but do not block if it fails.
lock_may_be_available in ./memcache-lock-code.inc
Check if lock acquired by a different process may be available.
lock_release in ./memcache-lock-code.inc
Release a lock previously acquired by lock_acquire().

... See full list

File

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

Code

function dmemcache_get($key, $bin = 'cache', $mc = NULL) {
  static $memcache_ascii_auth = NULL;
  $collect_stats = dmemcache_stats_init();
  $result = FALSE;
  $full_key = dmemcache_key($key, $bin);
  if ($mc || ($mc = dmemcache_object($bin))) {
    $track_errors = ini_set('track_errors', '1');
    $php_errormsg = '';
    $result = @$mc
      ->get($full_key);
    if (empty($result)) {
      if (!isset($memcache_ascii_auth)) {
        $memcache_ascii_auth = _dmemcache_use_ascii_auth();
      }
      if ($memcache_ascii_auth) {

        // As sets are costly we first check that the server is not authorized first.
        $rc = $mc
          ->getByKey($full_key, DRUPAL_MEMCACHE_ASCII_AUTH_LIFETIME_KEY);
        if (empty($rc) && _dmemcache_ensure_ascii_auth($full_key, $mc)) {
          $result = @$mc
            ->get($full_key);
        }
      }
    }

    // This is a multi-part value.
    if (is_object($result) && !empty($result->multi_part_data)) {
      $result = _dmemcache_get_pieces($result->data, $result->cid, $bin, $mc);
    }
    if (!empty($php_errormsg)) {
      register_shutdown_function('watchdog', 'memcache', 'Exception caught in dmemcache_get: !msg', array(
        '!msg' => $php_errormsg,
      ), WATCHDOG_WARNING);
      $php_errormsg = '';
    }
    ini_set('track_errors', $track_errors);
  }
  if ($collect_stats) {
    dmemcache_stats_write('get', $bin, array(
      $full_key => (bool) $result,
    ));
  }
  _dmemcache_write_debug('get', $bin, $full_key, (bool) $result);
  return $result;
}