3 namespace Drupal\Core\Cache\Context;
6 * Provides an interface for defining a calculated cache context service.
8 interface CalculatedCacheContextInterface {
11 * Returns the label of the cache context.
14 * The label of the cache context.
18 public static function getLabel();
21 * Returns the string representation of the cache context.
23 * A cache context service's name is used as a token (placeholder) cache key,
24 * and is then replaced with the string returned by this method.
26 * @param string|null $parameter
27 * The parameter, or NULL to indicate all possible parameter values.
30 * The string representation of the cache context. When $parameter is NULL,
31 * a value representing all possible parameters must be generated.
33 * @throws \LogicException
34 * Thrown if the passed in parameter is invalid.
36 public function getContext($parameter = NULL);
39 * Gets the cacheability metadata for the context based on the parameter value.
41 * There are three valid cases for the returned CacheableMetadata object:
42 * - An empty object means this can be optimized away safely.
43 * - A max-age of 0 means that this context can never be optimized away. It
44 * will never bubble up and cache tags will not be used.
45 * - Any non-zero max-age and cache tags will bubble up into the cache item
46 * if this is optimized away to allow for invalidation if the context
49 * @param string|null $parameter
50 * The parameter, or NULL to indicate all possible parameter values.
52 * @return \Drupal\Core\Cache\CacheableMetadata
53 * A cacheable metadata object.
55 * @throws \LogicException
56 * Thrown if the passed in parameter is invalid.
58 public function getCacheableMetadata($parameter = NULL);