You are here

class HeadersCacheContext in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php \Drupal\Core\Cache\Context\HeadersCacheContext

Defines the HeadersCacheContext service, for "per header" caching.

Cache context ID: 'headers' (to vary by all headers). Calculated cache context ID: 'headers:%name', e.g. 'headers:X-Something' (to vary by the 'X-Something' header).

Hierarchy

Expanded class hierarchy of HeadersCacheContext

1 string reference to 'HeadersCacheContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses HeadersCacheContext
cache_context.headers in core/core.services.yml
Drupal\Core\Cache\Context\HeadersCacheContext

File

core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php, line 19
Contains \Drupal\Core\Cache\Context\HeadersCacheContext.

Namespace

Drupal\Core\Cache\Context
View source
class HeadersCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('HTTP headers');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext($header = NULL) {
    if ($header === NULL) {
      return $this->requestStack
        ->getCurrentRequest()->headers
        ->all();
    }
    else {
      return $this->requestStack
        ->getCurrentRequest()->headers
        ->get($header);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($header = NULL) {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HeadersCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context based on the parameter value. Overrides CalculatedCacheContextInterface::getCacheableMetadata
HeadersCacheContext::getContext public function Returns the string representation of the cache context. Overrides CalculatedCacheContextInterface::getContext
HeadersCacheContext::getLabel public static function Returns the label of the cache context. Overrides CalculatedCacheContextInterface::getLabel
RequestStackCacheContextBase::$requestStack protected property The request stack.
RequestStackCacheContextBase::__construct public function Constructs a new RequestStackCacheContextBase class.