You are here

public static function MemcacheStorageAPI::replace in Memcache Storage 7

Replace existing data in memcache pool. Provide debug logging.

See also

http://www.php.net/manual/en/memcache.replace.php

1 call to MemcacheStorageAPI::replace()
lock_acquire in includes/lock.inc
Acquire (or renew) a lock, but do not block if it fails.

File

./memcache_storage.api.inc, line 344
Provide class that processes memcached operations.

Class

MemcacheStorageAPI
Integrates with memcache API.

Code

public static function replace($cache_id, $data, $expire, $cache_bin = '') {

  // Get memcache object.
  $memcache = self::openConnection($cache_bin);

  // No memcache connection.
  if (empty($memcache)) {
    return FALSE;
  }

  // Build unique cache id.
  $cid = self::preprocessCacheKey($cache_id, $cache_bin);

  // Run initial debug actions.
  if (variable_get('memcache_storage_debug', FALSE)) {
    self::initialDebugActions();
  }

  // Replace data if exists.
  $result = FALSE;
  if ($memcache instanceof Memcache) {

    // Get compression mode.
    $compressed = variable_get('memcache_storage_compress_data') ? MEMCACHE_COMPRESSED : 0;
    $result = @$memcache
      ->replace($cid, $data, $compressed, $expire);
  }
  elseif ($memcache instanceof Memcached) {
    $result = @$memcache
      ->replace($cid, $data, $expire);
  }

  // Run final debug actions.
  if (variable_get('memcache_storage_debug', FALSE)) {
    self::finalDebugActions('replace', $cache_bin, $cache_id, $cid, $result);
  }
  return $result;
}