CacheableResponseInterface.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Drupal\Core\Cache;
  3. /**
  4. * Defines an interface for responses that can expose cacheability metadata.
  5. *
  6. * @see \Drupal\Core\Cache\CacheableResponseTrait
  7. */
  8. interface CacheableResponseInterface {
  9. /**
  10. * Adds a dependency on an object: merges its cacheability metadata.
  11. *
  12. * For instance, when a response depends on some configuration, an entity, or
  13. * an access result, we must make sure their cacheability metadata is present
  14. * on the response. This method makes doing that simple.
  15. *
  16. * @param \Drupal\Core\Cache\CacheableDependencyInterface|mixed $dependency
  17. * The dependency. If the object implements CacheableDependencyInterface,
  18. * then its cacheability metadata will be used. Otherwise, the passed in
  19. * object must be assumed to be uncacheable, so max-age 0 is set.
  20. *
  21. * @return $this
  22. *
  23. * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject()
  24. */
  25. public function addCacheableDependency($dependency);
  26. /**
  27. * Returns the cacheability metadata for this response.
  28. *
  29. * @return \Drupal\Core\Cache\CacheableMetadata
  30. */
  31. public function getCacheableMetadata();
  32. }