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

Breadcrumb

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

class 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 extends \Drupal\Core\Cache\Context\RequestStackCacheContextBase implements \Drupal\Core\Cache\Context\CacheContextInterface

Expanded class hierarchy of PathCacheContext

See also

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

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

File

core/lib/Drupal/Core/Cache/Context/PathCacheContext.php, line 17

Namespace

Drupal\Core\Cache\Context
View 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

Title Sort descending Modifiers Object type Summary Overriden Title
PathCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
PathCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
PathCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
RequestStackCacheContextBase::$requestStack protected property The request stack.
RequestStackCacheContextBase::__construct public function Constructs a new RequestStackCacheContextBase class.

API Navigation

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