diff --git a/src/MemcacheBackend.php b/src/MemcacheBackend.php index da1bc43..836c801 100644 --- a/src/MemcacheBackend.php +++ b/src/MemcacheBackend.php @@ -102,7 +102,7 @@ class MemcacheBackend implements CacheBackendInterface { * {@inheritdoc} */ public function getMultiple(&$cids, $allow_invalid = FALSE) { - $keys = array_map(function($cid) { + $keys = array_map(function ($cid) { return $this->key($cid); }, $cids); @@ -117,7 +117,7 @@ class MemcacheBackend implements CacheBackendInterface { if ($result->data instanceof MultipartItem) { $childCIDs = $result->data->getCids(); $dataParts = $this->memcache->getMulti($childCIDs); - if(count($dataParts) !== count($childCIDs)) { + if (count($dataParts) !== count($childCIDs)) { // We're missing a chunk of the original entry. It is not valid. continue; } @@ -222,14 +222,14 @@ class MemcacheBackend implements CacheBackendInterface { $cache->checksum = $this->checksumProvider->getCurrentChecksum($tags); // Cache all items permanently. We handle expiration in our own logic. - if($this->memcache->set($this->key($cid), $cache)) { + if ($this->memcache->set($this->key($cid), $cache)) { return TRUE; } // Assume that the item is too large. We need to split it into multiple // chunks with a parent entry referencing all the chunks. $childKeys = []; - foreach($this->splitItem($cache) as $part) { + foreach ($this->splitItem($cache) as $part) { $childKey = $this->key($part->cid); // If a single chunk fails to be set, stop trying - we can't reconstitute diff --git a/src/MultipartItem.php b/src/MultipartItem.php index a72fef6..63af183 100644 --- a/src/MultipartItem.php +++ b/src/MultipartItem.php @@ -3,14 +3,33 @@ namespace Drupal\memcache; - +/** + * Wrapper for a split cache item. + * + * When a cache item is larger than Memcache can handle as a single item, it + * gets split into smaller chunks and stored as multiple items. An object of + * this class gets stored with the original CID - it does not contain data + * itself, but tracks the CIDs of the children that contain the data. + */ class MultipartItem { private $cids; + /** + * Constructor. + * + * @param string[] $cids + * The CIDs that contain the item's data. + */ public function __construct(array $cids) { $this->cids = $cids; } + /** + * Get the CIDs of this item's children. + * + * @return string[] + * The CIDs that contain the item's data. + */ public function getCids() { return $this->cids; }