class PathCacheContext in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Cache/Context/PathCacheContext.php \Drupal\Core\Cache\Context\PathCacheContext
- 9 core/lib/Drupal/Core/Cache/Context/PathCacheContext.php \Drupal\Core\Cache\Context\PathCacheContext
Defines the PathCacheContext service, for "per URL path" caching.
Cache context ID: 'url.path'.
(This allows for caching relative URLs.)
Hierarchy
- class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
- class \Drupal\Core\Cache\Context\PathCacheContext implements CacheContextInterface
Expanded class hierarchy of PathCacheContext
See also
\Symfony\Component\HttpFoundation\Request::getBasePath()
\Symfony\Component\HttpFoundation\Request::getPathInfo()
1 string reference to 'PathCacheContext'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses PathCacheContext
File
- core/
lib/ Drupal/ Core/ Cache/ Context/ PathCacheContext.php, line 17
Namespace
Drupal\Core\Cache\ContextView source
class PathCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Path');
}
/**
* {@inheritdoc}
*/
public function getContext() {
$request = $this->requestStack
->getCurrentRequest();
return $request
->getBasePath() . $request
->getPathInfo();
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
PathCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
PathCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
RequestStackCacheContextBase:: |
protected | property | The request stack. | |
RequestStackCacheContextBase:: |
public | function | Constructs a new RequestStackCacheContextBase class. |