function _dmemcache_get_pieces in Memcache API and Integration 7
Same name and namespace in other branches
- 6 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 340 - A memcache API for Drupal.
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 and append them together.
$pieces = dmemcache_get_multi($keys, $bin, $mc);
$data = '';
foreach ($pieces as $piece) {
// The piece may be NULL if it didn't exist in memcache. If so,
// we have to just return false for the entire set because we won't
// be able to reconstruct the original data without all the pieces.
if (!$piece) {
return FALSE;
}
$data .= $piece->data;
}
unset($pieces);
// If necessary unserialize the item.
if (empty($item->serialized)) {
return $data;
}
else {
$unserialize_function = dmemcache_unserialize();
return $unserialize_function($data);
}
}