diff --git a/core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php b/core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php index c8b102717d..c6a235215c 100644 --- a/core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Cache\Context; use Drupal\Component\Utility\Crypt; +use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * Defines the SessionCacheContext service, for "per session" caching. @@ -22,8 +23,11 @@ public static function getLabel() { * {@inheritdoc} */ public function getContext() { - $sid = $this->requestStack->getCurrentRequest()->getSession()->getId(); - return Crypt::hashBase64($sid); + $session = $this->requestStack->getCurrentRequest()->getSession(); + if ($session instanceof SessionInterface) { + return Crypt::hashBase64($session->getId()); + } + return Crypt::hashBase64(1); } }