You are here

class SiteCacheContext in Zircon Profile 8

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

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

Cache context ID: '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 25
Contains \Drupal\Core\Cache\Context\SiteCacheContext.

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