public CacheableMetadata::merge(CacheableMetadata $other)
Merges the values of another CacheableMetadata object with this one.
\Drupal\Core\Cache\CacheableMetadata $other: The other CacheableMetadata object.
static A new CacheableMetadata object, with the merged data.
public function merge(CacheableMetadata $other) { $result = clone $this; // This is called many times per request, so avoid merging unless absolutely // necessary. if (empty($this->cacheContexts)) { $result->cacheContexts = $other->cacheContexts; } elseif (empty($other->cacheContexts)) { $result->cacheContexts = $this->cacheContexts; } else { $result->cacheContexts = Cache::mergeContexts($this->cacheContexts, $other->cacheContexts); } if (empty($this->cacheTags)) { $result->cacheTags = $other->cacheTags; } elseif (empty($other->cacheTags)) { $result->cacheTags = $this->cacheTags; } else { $result->cacheTags = Cache::mergeTags($this->cacheTags, $other->cacheTags); } if ($this->cacheMaxAge === Cache::PERMANENT) { $result->cacheMaxAge = $other->cacheMaxAge; } elseif ($other->cacheMaxAge === Cache::PERMANENT) { $result->cacheMaxAge = $this->cacheMaxAge; } else { $result->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $other->cacheMaxAge); } return $result; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cache!CacheableMetadata.php/function/CacheableMetadata::merge/8.1.x