trait RefinableCacheableDependencyTrait

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php \Drupal\Core\Cache\RefinableCacheableDependencyTrait
  2. 8.9.x core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php \Drupal\Core\Cache\RefinableCacheableDependencyTrait
  3. 10 core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php \Drupal\Core\Cache\RefinableCacheableDependencyTrait

Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.

Hierarchy

9 files declare their use of RefinableCacheableDependencyTrait
AccessResult.php in core/lib/Drupal/Core/Access/AccessResult.php
Breadcrumb.php in core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php
ComputedTestCacheableString.php in core/modules/system/tests/modules/entity_test/src/Plugin/DataType/ComputedTestCacheableString.php
ConfigBase.php in core/lib/Drupal/Core/Config/ConfigBase.php
EntityBase.php in core/lib/Drupal/Core/Entity/EntityBase.php

... See full list

File

core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php, line 8

Namespace

Drupal\Core\Cache
View source
trait RefinableCacheableDependencyTrait {
    use CacheableDependencyTrait;
    
    /**
     * {@inheritdoc}
     */
    public function addCacheableDependency($other_object) {
        if ($other_object instanceof CacheableDependencyInterface) {
            $this->addCacheContexts($other_object->getCacheContexts());
            $this->addCacheTags($other_object->getCacheTags());
            $this->mergeCacheMaxAge($other_object->getCacheMaxAge());
        }
        else {
            // Not a cacheable dependency, this can not be cached.
            $this->cacheMaxAge = 0;
        }
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function addCacheContexts(array $cache_contexts) {
        if ($cache_contexts) {
            $this->cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts);
        }
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function addCacheTags(array $cache_tags) {
        if ($cache_tags) {
            $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags);
        }
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function mergeCacheMaxAge($max_age) {
        $this->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $max_age);
        return $this;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 4
CacheableDependencyTrait::getCacheMaxAge public function 4
CacheableDependencyTrait::getCacheTags public function 4
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.