Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SiteCacheContext.php

class 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

  • class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
    • class \Drupal\Core\Cache\Context\SiteCacheContext extends \Drupal\Core\Cache\Context\RequestStackCacheContextBase implements \Drupal\Core\Cache\Context\CacheContextInterface

Expanded class hierarchy of SiteCacheContext

See also

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

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

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

Title Sort descending Modifiers Object type Summary Overriden Title
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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal