CalculatedCacheContextInterface.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Drupal\Core\Cache\Context;
  3. /**
  4. * Provides an interface for defining a calculated cache context service.
  5. */
  6. interface CalculatedCacheContextInterface {
  7. /**
  8. * Returns the label of the cache context.
  9. *
  10. * @return string
  11. * The label of the cache context.
  12. *
  13. * @see Cache
  14. */
  15. public static function getLabel();
  16. /**
  17. * Returns the string representation of the cache context.
  18. *
  19. * A cache context service's name is used as a token (placeholder) cache key,
  20. * and is then replaced with the string returned by this method.
  21. *
  22. * @param string|null $parameter
  23. * The parameter, or NULL to indicate all possible parameter values.
  24. *
  25. * @return string
  26. * The string representation of the cache context. When $parameter is NULL,
  27. * a value representing all possible parameters must be generated.
  28. *
  29. * @throws \LogicException
  30. * Thrown if the passed in parameter is invalid.
  31. */
  32. public function getContext($parameter = NULL);
  33. /**
  34. * Gets the cacheability metadata for the context based on the parameter value.
  35. *
  36. * There are three valid cases for the returned CacheableMetadata object:
  37. * - An empty object means this can be optimized away safely.
  38. * - A max-age of 0 means that this context can never be optimized away. It
  39. * will never bubble up and cache tags will not be used.
  40. * - Any non-zero max-age and cache tags will bubble up into the cache item
  41. * if this is optimized away to allow for invalidation if the context
  42. * value changes.
  43. *
  44. * @param string|null $parameter
  45. * The parameter, or NULL to indicate all possible parameter values.
  46. *
  47. * @return \Drupal\Core\Cache\CacheableMetadata
  48. * A cacheable metadata object.
  49. *
  50. * @throws \LogicException
  51. * Thrown if the passed in parameter is invalid.
  52. */
  53. public function getCacheableMetadata($parameter = NULL);
  54. }