diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php
index dd0cea1372ad92096dab06b625342a4feb5f2c06..8bb7e757f6757dab6da831416cfc5eeb83533f4a 100644
--- a/core/lib/Drupal/Core/Cache/MemoryBackend.php
+++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php
@@ -29,13 +29,25 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
    */
   protected $cache = [];
 
+  /**
+   * @var \Drupal\Component\Datetime\TimeInterface
+   */
+  protected TimeInterface $time;
+
   /**
    * Constructs a MemoryBackend object.
    *
-   * @param \Drupal\Component\Datetime\TimeInterface $time
+   * @param \Drupal\Component\Datetime\TimeInterface|null $time
    *   The time service.
    */
-  public function __construct(protected TimeInterface $time) {
+  public function __construct(?TimeInterface $time = NULL) {
+    // Gracefully handle legacy calls to the constructor without a time service.
+    if ($time === NULL) {
+      $this->time = \Drupal::time();
+    }
+    else {
+      $this->time = $time;
+    }
   }
 
   /**
@@ -198,8 +210,7 @@ public function invalidateAll() {
   /**
    * {@inheritdoc}
    */
-  public function garbageCollection() {
-  }
+  public function garbageCollection() {}
 
   /**
    * {@inheritdoc}