You are here

class SiteCacheContext in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php \Drupal\Core\Cache\Context\SiteCacheContext
  2. 9 core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php \Drupal\Core\Cache\Context\SiteCacheContext

Defines the SiteCacheContext service, for "per site" caching.

Cache context ID: 'url.site'.

A "site" is defined as the combination of URI scheme, domain name, port and base path. It allows for varying between the *same* site being accessed via different entry points. (Different sites in a multisite setup have separate databases.) For example: http://example.com and http://www.example.com.

Hierarchy

Expanded class hierarchy of SiteCacheContext

See also

\Symfony\Component\HttpFoundation\Request::getSchemeAndHttpHost()

\Symfony\Component\HttpFoundation\Request::getBaseUrl()

1 string reference to 'SiteCacheContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses SiteCacheContext
cache_context.url.site in core/core.services.yml
Drupal\Core\Cache\Context\SiteCacheContext

File

core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php, line 20

Namespace

Drupal\Core\Cache\Context
View source
class SiteCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {

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

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    $request = $this->requestStack
      ->getCurrentRequest();
    return $request
      ->getSchemeAndHttpHost() . $request
      ->getBaseUrl();
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

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