3 namespace Drupal\Core\Cache;
6 * Provides an implementation of CacheableResponseInterface.
8 * @see \Drupal\Core\Cache\CacheableResponseInterface
10 trait CacheableResponseTrait {
13 * The cacheability metadata.
15 * @var \Drupal\Core\Cache\CacheableMetadata
17 protected $cacheabilityMetadata;
22 public function addCacheableDependency($dependency) {
23 // A trait doesn't have a constructor, so initialize the cacheability
24 // metadata if that hasn't happened yet.
25 if (!isset($this->cacheabilityMetadata)) {
26 $this->cacheabilityMetadata = new CacheableMetadata();
29 $this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheableMetadata::createFromObject($dependency));
37 public function getCacheableMetadata() {
38 // A trait doesn't have a constructor, so initialize the cacheability
39 // metadata if that hasn't happened yet.
40 if (!isset($this->cacheabilityMetadata)) {
41 $this->cacheabilityMetadata = new CacheableMetadata();
44 return $this->cacheabilityMetadata;