annotate core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Cache;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.
Chris@0 7 */
Chris@0 8 trait RefinableCacheableDependencyTrait {
Chris@0 9
Chris@14 10 use CacheableDependencyTrait;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * {@inheritdoc}
Chris@0 14 */
Chris@0 15 public function addCacheableDependency($other_object) {
Chris@0 16 if ($other_object instanceof CacheableDependencyInterface) {
Chris@0 17 $this->addCacheContexts($other_object->getCacheContexts());
Chris@0 18 $this->addCacheTags($other_object->getCacheTags());
Chris@0 19 $this->mergeCacheMaxAge($other_object->getCacheMaxAge());
Chris@0 20 }
Chris@0 21 else {
Chris@0 22 // Not a cacheable dependency, this can not be cached.
Chris@0 23 $this->cacheMaxAge = 0;
Chris@0 24 }
Chris@0 25 return $this;
Chris@0 26 }
Chris@0 27
Chris@0 28 /**
Chris@0 29 * {@inheritdoc}
Chris@0 30 */
Chris@0 31 public function addCacheContexts(array $cache_contexts) {
Chris@0 32 if ($cache_contexts) {
Chris@0 33 $this->cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts);
Chris@0 34 }
Chris@0 35 return $this;
Chris@0 36 }
Chris@0 37
Chris@0 38 /**
Chris@0 39 * {@inheritdoc}
Chris@0 40 */
Chris@0 41 public function addCacheTags(array $cache_tags) {
Chris@0 42 if ($cache_tags) {
Chris@0 43 $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags);
Chris@0 44 }
Chris@0 45 return $this;
Chris@0 46 }
Chris@0 47
Chris@0 48 /**
Chris@0 49 * {@inheritdoc}
Chris@0 50 */
Chris@0 51 public function mergeCacheMaxAge($max_age) {
Chris@0 52 $this->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $max_age);
Chris@0 53 return $this;
Chris@0 54 }
Chris@0 55
Chris@0 56 }