3 namespace Drupal\Core\Cache\Context;
5 use Drupal\Core\Cache\CacheableMetadata;
8 * Defines the PathCacheContext service, for "per URL path" caching.
10 * Cache context ID: 'url.path'.
12 * (This allows for caching relative URLs.)
14 * @see \Symfony\Component\HttpFoundation\Request::getBasePath()
15 * @see \Symfony\Component\HttpFoundation\Request::getPathInfo()
17 class PathCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
22 public static function getLabel() {
29 public function getContext() {
30 $request = $this->requestStack->getCurrentRequest();
31 return $request->getBasePath() . $request->getPathInfo();
37 public function getCacheableMetadata() {
38 return new CacheableMetadata();