ProtocolVersionCacheContext.php

Same filename and directory in other branches
  1. 9 core/lib/Drupal/Core/Cache/Context/ProtocolVersionCacheContext.php
  2. 10 core/lib/Drupal/Core/Cache/Context/ProtocolVersionCacheContext.php
  3. 11.x core/lib/Drupal/Core/Cache/Context/ProtocolVersionCacheContext.php

Namespace

Drupal\Core\Cache\Context

File

core/lib/Drupal/Core/Cache/Context/ProtocolVersionCacheContext.php

View source
<?php

namespace Drupal\Core\Cache\Context;

use Drupal\Core\Cache\CacheableMetadata;

/**
 * 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'.
 */
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();
    }

}

Classes

Title Deprecated Summary
ProtocolVersionCacheContext Defines the ProtocolVersionCacheContext service, for "per protocol" caching.

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