You are here

trait CacheableDependencyTrait in JSON:API 8

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

@internal

Hierarchy

Deprecated

Remove when JSON API requires Drupal 8.5 or newer, update all users to \Drupal\Core\Cache\CacheableDependencyTrait instead.

4 files declare their use of CacheableDependencyTrait
EntityNormalizerValue.php in src/Normalizer/Value/EntityNormalizerValue.php
FieldItemNormalizerValue.php in src/Normalizer/Value/FieldItemNormalizerValue.php
FieldNormalizerValue.php in src/Normalizer/Value/FieldNormalizerValue.php
NullFieldNormalizerValue.php in src/Normalizer/Value/NullFieldNormalizerValue.php

File

src/Normalizer/CacheableDependencyTrait.php, line 14

Namespace

Drupal\jsonapi\Normalizer
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
CacheableDependencyTrait::getCacheMaxAge public function
CacheableDependencyTrait::getCacheTags public function
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.