diff --git a/core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php b/core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php
index c8b1027..8d5b020 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);
+    $sid = $this->requestStack->getCurrentRequest()->getSession();
+    if ($sid instanceof SessionInterface) {
+      return Crypt::hashBase64($sid->getId());
+    }
+    return Crypt::hashBase64(1);
   }
 
 }
