diff --git a/core/lib/Drupal/Core/Cache/CacheFactory.php b/core/lib/Drupal/Core/Cache/CacheFactory.php index c8eebbb..ec7b066 100644 --- a/core/lib/Drupal/Core/Cache/CacheFactory.php +++ b/core/lib/Drupal/Core/Cache/CacheFactory.php @@ -75,13 +75,14 @@ public function __construct(Settings $settings, array $default_bin_backends = [] * The cache backend object associated with the specified bin. */ public function get($bin) { - // Disable caching during Drupal installation. + $cache_settings = $this->settings->get('cache'); + // Use memory caching during Drupal installation to avoid thousands of + // unnecessary database queries. if ($this->installationAttempted) { - return new NullBackend($bin); + $service_name = 'cache.backend.memory'; } - $cache_settings = $this->settings->get('cache'); // First, look for a cache bin specific setting. - if (isset($cache_settings['bins'][$bin])) { + elseif (isset($cache_settings['bins'][$bin])) { $service_name = $cache_settings['bins'][$bin]; } // Second, use the default backend specified by the cache bin. diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php index ab0d1b0..dd2f368 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\Core\Cache; use Drupal\Core\Cache\CacheFactoryInterface; -use Drupal\Core\Cache\NullBackend; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Cache\CacheFactory; use Drupal\Core\Site\Settings; @@ -163,8 +162,11 @@ public function testCacheFactoryDuringInstaller() { $builtin_default_backend_factory = $this->prophesize(CacheFactoryInterface::class); $builtin_default_backend_factory->get()->shouldNotBeCalled(); $container->set('cache.backend.database', $builtin_default_backend_factory->reveal()); - $actual_bin = $cache_factory->get('render'); - $this->assertInstanceOf(NullBackend::class, $actual_bin); + $memory_backend_factory = $this->prophesize(CacheFactoryInterface::class); + $memory_backend_factory->get('render')->shouldBeCalled(); + $container->set('cache.backend.memory', $memory_backend_factory->reveal()); + + $cache_factory->get('render'); } }