trait CacheableDependencyTrait
Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
Hierarchy
- trait \Drupal\Core\Cache\CacheableDependencyTrait
21 files declare their use of CacheableDependencyTrait
- Broken.php in core/lib/ Drupal/ Core/ Block/ Plugin/ Block/ Broken.php 
- CacheableAccessDeniedHttpException.php in core/lib/ Drupal/ Core/ Http/ Exception/ CacheableAccessDeniedHttpException.php 
- CacheableBadRequestHttpException.php in core/lib/ Drupal/ Core/ Http/ Exception/ CacheableBadRequestHttpException.php 
- CacheableConflictHttpException.php in core/lib/ Drupal/ Core/ Http/ Exception/ CacheableConflictHttpException.php 
- CacheableGoneHttpException.php in core/lib/ Drupal/ Core/ Http/ Exception/ CacheableGoneHttpException.php 
File
- 
              core/lib/ Drupal/ Core/ Cache/ CacheableDependencyTrait.php, line 8 
Namespace
Drupal\Core\CacheView source
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;
  }
}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. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
