You are here

trait CacheableDependencyTrait in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php \Drupal\Core\Cache\CacheableDependencyTrait
  2. 9 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