CacheContextInterface.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Drupal\Core\Cache\Context;
  3. /**
  4. * Provides an interface for defining a cache context service.
  5. */
  6. interface CacheContextInterface {
  7. /**
  8. * Returns the label of the cache context.
  9. *
  10. * @return string
  11. * The label of the cache context.
  12. */
  13. public static function getLabel();
  14. /**
  15. * Returns the string representation of the cache context.
  16. *
  17. * A cache context service's name is used as a token (placeholder) cache key,
  18. * and is then replaced with the string returned by this method.
  19. *
  20. * @return string
  21. * The string representation of the cache context.
  22. */
  23. public function getContext();
  24. /**
  25. * Gets the cacheability metadata for the context.
  26. *
  27. * There are three valid cases for the returned CacheableMetadata object:
  28. * - An empty object means this can be optimized away safely.
  29. * - A max-age of 0 means that this context can never be optimized away. It
  30. * will never bubble up and cache tags will not be used.
  31. * - Any non-zero max-age and cache tags will bubble up into the cache item
  32. * if this is optimized away to allow for invalidation if the context
  33. * value changes.
  34. *
  35. *
  36. * @return \Drupal\Core\Cache\CacheableMetadata
  37. * A cacheable metadata object.
  38. */
  39. public function getCacheableMetadata();
  40. }