3 namespace Drupal\Core\Cache\Context;
6 * Provides an interface for defining a cache context service.
8 interface CacheContextInterface {
11 * Returns the label of the cache context.
14 * The label of the cache context.
16 public static function getLabel();
19 * Returns the string representation of the cache context.
21 * A cache context service's name is used as a token (placeholder) cache key,
22 * and is then replaced with the string returned by this method.
25 * The string representation of the cache context.
27 public function getContext();
30 * Gets the cacheability metadata for the context.
32 * There are three valid cases for the returned CacheableMetadata object:
33 * - An empty object means this can be optimized away safely.
34 * - A max-age of 0 means that this context can never be optimized away. It
35 * will never bubble up and cache tags will not be used.
36 * - Any non-zero max-age and cache tags will bubble up into the cache item
37 * if this is optimized away to allow for invalidation if the context
41 * @return \Drupal\Core\Cache\CacheableMetadata
42 * A cacheable metadata object.
44 public function getCacheableMetadata();