RefinableCacheableDependencyInterface.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Drupal\Core\Cache;
  3. /**
  4. * Allows to add cacheability metadata to an object for the current runtime.
  5. *
  6. * This must be used when changing an object in a way that affects its
  7. * cacheability. For example, when changing the active translation of an entity
  8. * based on the current content language then a cache context for that must be
  9. * added.
  10. */
  11. interface RefinableCacheableDependencyInterface extends CacheableDependencyInterface {
  12. /**
  13. * Adds cache contexts.
  14. *
  15. * @param string[] $cache_contexts
  16. * The cache contexts to be added.
  17. *
  18. * @return $this
  19. */
  20. public function addCacheContexts(array $cache_contexts);
  21. /**
  22. * Adds cache tags.
  23. *
  24. * @param string[] $cache_tags
  25. * The cache tags to be added.
  26. *
  27. * @return $this
  28. */
  29. public function addCacheTags(array $cache_tags);
  30. /**
  31. * Merges the maximum age (in seconds) with the existing maximum age.
  32. *
  33. * The max age will be set to the given value if it is lower than the existing
  34. * value.
  35. *
  36. * @param int $max_age
  37. * The max age to associate.
  38. *
  39. * @return $this
  40. *
  41. * @throws \InvalidArgumentException
  42. * Thrown if a non-integer value is supplied.
  43. */
  44. public function mergeCacheMaxAge($max_age);
  45. /**
  46. * Adds a dependency on an object: merges its cacheability metadata.
  47. *
  48. * @param \Drupal\Core\Cache\CacheableDependencyInterface|object $other_object
  49. * The dependency. If the object implements CacheableDependencyInterface,
  50. * then its cacheability metadata will be used. Otherwise, the passed in
  51. * object must be assumed to be uncacheable, so max-age 0 is set.
  52. *
  53. * @return $this
  54. *
  55. * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject()
  56. */
  57. public function addCacheableDependency($other_object);
  58. }