You are here

function _dmemcache_get_pieces in Memcache API and Integration 6

Same name and namespace in other branches
  1. 7 dmemcache.inc \_dmemcache_get_pieces()

Retrieve a value from the cache.

Parameters

$item: The placeholder cache item from _dmemcache_set_pieces().

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

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

object $mc: (optional) The memcache object. Normally this value is determined automatically based on the bin the object is being stored to.

Return value

object|bool The item which was originally saved or FALSE.

2 calls to _dmemcache_get_pieces()
dmemcache_get in ./dmemcache.inc
Retrieve a value from the cache.
dmemcache_get_multi in ./dmemcache.inc
Retrieve multiple values from the cache.

File

./dmemcache.inc, line 292

Code

function _dmemcache_get_pieces($item, $key, $bin = 'cache', $mc = NULL) {

  // Create a list of keys for the pieces of data.
  for ($id = 0; $id < $item->piece_count; $id++) {
    $keys[] = _dmemcache_key_piece($key, $id);
  }

  // Retrieve all the pieces of data.
  $pieces = dmemcache_get_multi($keys, $bin, $mc);
  if (count($pieces) != $item->piece_count) {

    // Some of the pieces don't exist, so our data cannot be reconstructed.
    return FALSE;
  }

  // Append all of the pieces together.
  $data = '';
  foreach ($pieces as $piece) {
    $data .= $piece->data;
  }
  unset($pieces);

  // If necessary unserialize the item.
  return empty($item->serialized) ? $data : unserialize($data);
}