private function MemcacheBackend::splitItem in Memcache API and Integration 8.2
Given a single cache item, split it into multiple child items.
Parameters
\stdClass $item: The original cache item, before the split.
Return value
\stdClass[] An array of child items.
1 call to MemcacheBackend::splitItem()
- MemcacheBackend::set in src/
MemcacheBackend.php - Stores data in the persistent cache.
File
- src/
MemcacheBackend.php, line 246
Class
- MemcacheBackend
- Defines a Memcache cache backend.
Namespace
Drupal\memcacheCode
private function splitItem(\stdClass $item) {
$data = serialize($item->data);
$pieces = str_split($data, static::MAX_CHUNK_SIZE);
// Add a unique identifier each time this function is invoked. This
// prevents a race condition where two sets on the same multipart item can
// clobber each other's children. With this seed, each time a multipart
// entry is created, they get a different CID. The parent (multipart) entry
// does not inherit this unique identifier, so it is still addressable using
// the CID it was initially given.
$seed = Crypt::randomBytesBase64();
$children = [];
foreach ($pieces as $i => $chunk) {
// Child items do not need tags or expire, since that data is carried by
// the parent.
$chunkItem = new \stdClass();
// @TODO: mention why we added split and picked this order...
$chunkItem->cid = sprintf('split.%d.%s.%s', $i, $item->cid, $seed);
$chunkItem->data = $chunk;
$chunkItem->created = $item->created;
$children[] = $chunkItem;
}
if ($this
->debug()) {
$this
->getLogger('memcache')
->debug('Split item @cid into @num pieces', [
'@cid' => $item->cid,
'@num' => $i + 1,
]);
}
return $children;
}