diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
index c7848e2..b8a502c 100644
--- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
+++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
@@ -78,7 +78,7 @@ class ExtensionDiscovery {
   protected $profileDirectories;
 
   /**
-   * The app root.
+   * The app root for the current operation.
    *
    * @var string
    */
@@ -208,12 +208,12 @@ public function scan($type, $include_tests = NULL) {
     $files = array();
     foreach ($searchdirs as $dir) {
       // Discover all extensions in the directory, unless we did already.
-      if (!isset(static::$files[$dir][$include_tests])) {
-        static::$files[$dir][$include_tests] = $this->scanDirectory($dir, $include_tests);
+      if (!isset(static::$files[$this->root][$dir][$include_tests])) {
+        static::$files[$this->root][$dir][$include_tests] = $this->scanDirectory($dir, $include_tests);
       }
       // Only return extensions of the requested type.
-      if (isset(static::$files[$dir][$include_tests][$type])) {
-        $files += static::$files[$dir][$include_tests][$type];
+      if (isset(static::$files[$this->root][$dir][$include_tests][$type])) {
+        $files += static::$files[$this->root][$dir][$include_tests][$type];
       }
     }
 
diff --git a/core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php
new file mode 100644
index 0000000..919603d
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace Drupal\Tests\Core\Extension;
+
+use Drupal\Core\Extension\ExtensionDiscovery;
+use Drupal\Tests\UnitTestCase;
+use org\bovigo\vfs\vfsStream;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Extension\ExtensionDiscovery
+ * @group Extension
+ */
+class ExtensionDiscoveryTest extends UnitTestCase {
+
+  /**
+   * Provides a stub file system for a single module in sites/all.
+   *
+   * @return array
+   *   An array representing a virtual filesystem containing a module.
+   */
+  public function providerModule() {
+    $info_a = <<<'EOS'
+type: module
+name: Module A
+core: 8.x
+EOS;
+    return [
+      [
+        'sites' => [
+          'default' => [
+            'modules' => [
+              'module_a' => [
+                'module_a.info.yml' => $info_a
+              ],
+            ],
+          ],
+        ],
+      ],
+    ];
+  }
+
+  /**
+   * Check that the cache uses different keys for different root directories.
+   *
+   * @covers ::scan
+   *
+   * @dataProvider providerModule
+   */
+  public function testScanCacheKeys($filesystem) {
+    vfsStream::setup('root');
+
+    // Create the same filesystem in two different directories.
+    vfsStream::create($filesystem, vfsStream::newDirectory('test1'));
+    vfsStream::create($filesystem, vfsStream::newDirectory('test2'));
+
+    $root_1 = vfsStream::url('root/test1');
+    $root_2 = vfsStream::url('root/test2');
+
+    // Create an ExtensionDiscovery with $root_1.
+    $extension_discovery = new ExtensionDiscovery($root_1, TRUE, ['no/profile'], 'sites/default');
+
+    // Assert that the cache does not contain either key we're looking for until
+    // after we've performed a scan.
+    $this->assertArrayNotHasKey($root_1, $this->getDiscoveredCache($extension_discovery));
+    $this->assertArrayNotHasKey($root_2, $this->getDiscoveredCache($extension_discovery));
+
+    // Perform the scan.
+    $extension_discovery->scan('module');
+
+    // Assert that we have $root_1 as a key, but not $root_2 yet.
+    $this->assertArrayHasKey($root_1, $this->getDiscoveredCache($extension_discovery));
+    $this->assertArrayNotHasKey($root_2, $this->getDiscoveredCache($extension_discovery));
+
+    // Re-instantiate ExtensionDiscovery with a different root.
+    $extension_discovery = new ExtensionDiscovery($root_2, TRUE, ['no/profile'], 'sites/default');
+
+    // Since the cache is static, it will still only have $root_1.
+    $this->assertArrayHasKey($root_1, $this->getDiscoveredCache($extension_discovery));
+    $this->assertArrayNotHasKey($root_2, $this->getDiscoveredCache($extension_discovery));
+
+    // Perform the scan.
+    $extension_discovery->scan('module');
+
+    // Now we have both keys in the cache array.
+    $this->assertArrayHasKey($root_1, $this->getDiscoveredCache($extension_discovery));
+    $this->assertArrayHasKey($root_2, $this->getDiscoveredCache($extension_discovery));
+  }
+
+  /**
+   * Helper method to get the cache array from an ExtensionDiscovery object.
+   *
+   * @param ExtensionDiscovery $extension_discovery
+   *   An ExtensionDiscovery object.
+   *
+   * @return array[]
+   *   The files array.
+   */
+  protected function getDiscoveredCache(ExtensionDiscovery $extension_discovery) {
+    $ref_cache = new \ReflectionProperty(ExtensionDiscovery::class, 'files');
+    $ref_cache->setAccessible(TRUE);
+    return $ref_cache->getValue($extension_discovery);
+  }
+
+}
