class SiteCacheContext in Drupal 9
Same name and namespace in other branches
- 8 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
- class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
- class \Drupal\Core\Cache\Context\SiteCacheContext implements CacheContextInterface
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
File
- core/
lib/ Drupal/ Core/ Cache/ Context/ SiteCacheContext.php, line 20
Namespace
Drupal\Core\Cache\ContextView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RequestStackCacheContextBase:: |
protected | property | The request stack. | |
RequestStackCacheContextBase:: |
public | function | Constructs a new RequestStackCacheContextBase class. | |
SiteCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
SiteCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
SiteCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |