CacheableDependencyTrait.php

Same filename and directory in other branches
  1. 9 core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php
  2. 10 core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php
  3. 11.x core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php

Namespace

Drupal\Core\Cache

File

core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php

View source
<?php

namespace Drupal\Core\Cache;


/**
 * Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
 */
trait CacheableDependencyTrait {
    
    /**
     * Cache contexts.
     *
     * @var string[]
     */
    protected $cacheContexts = [];
    
    /**
     * Cache tags.
     *
     * @var string[]
     */
    protected $cacheTags = [];
    
    /**
     * Cache max-age.
     *
     * @var int
     */
    protected $cacheMaxAge = Cache::PERMANENT;
    
    /**
     * Sets cacheability; useful for value object constructors.
     *
     * @param \Drupal\Core\Cache\CacheableDependencyInterface $cacheability
     *   The cacheability to set.
     *
     * @return $this
     */
    protected function setCacheability(CacheableDependencyInterface $cacheability) {
        $this->cacheContexts = $cacheability->getCacheContexts();
        $this->cacheTags = $cacheability->getCacheTags();
        $this->cacheMaxAge = $cacheability->getCacheMaxAge();
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheTags() {
        return $this->cacheTags;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheContexts() {
        return $this->cacheContexts;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheMaxAge() {
        return $this->cacheMaxAge;
    }

}

Traits

Title Deprecated Summary
CacheableDependencyTrait Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

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