class ProtocolVersionCacheContext

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Cache/Context/ProtocolVersionCacheContext.php \Drupal\Core\Cache\Context\ProtocolVersionCacheContext

Defines the ProtocolVersionCacheContext service, for "per protocol" caching.

Useful to differentiate between HTTP/1.1 and HTTP/2.0 responses for example, to allow responses to be optimized for protocol-specific characteristics.

Cache context ID: 'protocol_version'.

Hierarchy

Expanded class hierarchy of ProtocolVersionCacheContext

1 file declares its use of ProtocolVersionCacheContext
ProtocolVersionCacheContextTest.php in core/tests/Drupal/Tests/Core/Cache/Context/ProtocolVersionCacheContextTest.php
1 string reference to 'ProtocolVersionCacheContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ProtocolVersionCacheContext
cache_context.protocol_version in core/core.services.yml
Drupal\Core\Cache\Context\ProtocolVersionCacheContext

File

core/lib/Drupal/Core/Cache/Context/ProtocolVersionCacheContext.php, line 15

Namespace

Drupal\Core\Cache\Context
View source
class ProtocolVersionCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
  
  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Protocol version');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return $this->requestStack
      ->getCurrentRequest()
      ->getProtocolVersion();
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.