trait CacheableResponseTrait
Same name in other branches
- 9 core/lib/Drupal/Core/Cache/CacheableResponseTrait.php \Drupal\Core\Cache\CacheableResponseTrait
- 10 core/lib/Drupal/Core/Cache/CacheableResponseTrait.php \Drupal\Core\Cache\CacheableResponseTrait
- 11.x core/lib/Drupal/Core/Cache/CacheableResponseTrait.php \Drupal\Core\Cache\CacheableResponseTrait
Provides an implementation of CacheableResponseInterface.
Hierarchy
- trait \Drupal\Core\Cache\CacheableResponseTrait
See also
\Drupal\Core\Cache\CacheableResponseInterface
6 files declare their use of CacheableResponseTrait
- CacheableSecuredRedirectResponse.php in core/
lib/ Drupal/ Core/ Routing/ CacheableSecuredRedirectResponse.php - CacheableTestResponse.php in core/
modules/ system/ tests/ modules/ early_rendering_controller_test/ src/ CacheableTestResponse.php - HtmlResponse.php in core/
lib/ Drupal/ Core/ Render/ HtmlResponse.php - ResourceResponse.php in core/
modules/ jsonapi/ src/ ResourceResponse.php - ResourceResponse.php in core/
modules/ rest/ src/ ResourceResponse.php
File
-
core/
lib/ Drupal/ Core/ Cache/ CacheableResponseTrait.php, line 10
Namespace
Drupal\Core\CacheView source
trait CacheableResponseTrait {
/**
* The cacheability metadata.
*
* @var \Drupal\Core\Cache\CacheableMetadata
*/
protected $cacheabilityMetadata;
/**
* {@inheritdoc}
*/
public function addCacheableDependency($dependency) {
// A trait doesn't have a constructor, so initialize the cacheability
// metadata if that hasn't happened yet.
if (!isset($this->cacheabilityMetadata)) {
$this->cacheabilityMetadata = new CacheableMetadata();
}
$this->cacheabilityMetadata = $this->cacheabilityMetadata
->merge(CacheableMetadata::createFromObject($dependency));
return $this;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
// A trait doesn't have a constructor, so initialize the cacheability
// metadata if that hasn't happened yet.
if (!isset($this->cacheabilityMetadata)) {
$this->cacheabilityMetadata = new CacheableMetadata();
}
return $this->cacheabilityMetadata;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
CacheableResponseTrait::$cacheabilityMetadata | protected | property | The cacheability metadata. |
CacheableResponseTrait::addCacheableDependency | public | function | |
CacheableResponseTrait::getCacheableMetadata | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.