1<?php 2 3namespace Drupal\Core\Cache\Context; 4 5/** 6 * Provides an interface for defining a calculated cache context service. 7 */ 8interface CalculatedCacheContextInterface { 9 10 /** 11 * Returns the label of the cache context. 12 * 13 * @return string 14 * The label of the cache context. 15 * 16 * @see Cache 17 */ 18 public static function getLabel(); 19 20 /** 21 * Returns the string representation of the cache context. 22 * 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. 25 * 26 * @param string|null $parameter 27 * The parameter, or NULL to indicate all possible parameter values. 28 * 29 * @return string 30 * The string representation of the cache context. When $parameter is NULL, 31 * a value representing all possible parameters must be generated. 32 * 33 * @throws \LogicException 34 * Thrown if the passed in parameter is invalid. 35 */ 36 public function getContext($parameter = NULL); 37 38 /** 39 * Gets the cacheability metadata for the context based on the parameter value. 40 * 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 47 * value changes. 48 * 49 * @param string|null $parameter 50 * The parameter, or NULL to indicate all possible parameter values. 51 * 52 * @return \Drupal\Core\Cache\CacheableMetadata 53 * A cacheable metadata object. 54 * 55 * @throws \LogicException 56 * Thrown if the passed in parameter is invalid. 57 */ 58 public function getCacheableMetadata($parameter = NULL); 59 60} 61