You are here

trait CacheableDependencyTrait in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php \Drupal\Core\Cache\CacheableDependencyTrait

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

Hierarchy

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

... See full list

File

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

Namespace

Drupal\Core\Cache
View 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

Namesort descending Modifiers Type Description 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.