diff -u b/core/includes/cache.inc b/core/includes/cache.inc --- b/core/includes/cache.inc +++ b/core/includes/cache.inc @@ -7,6 +7,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheFactory; +use Drupal\Core\Cache\Cache; /** * Instantiates and statically caches the correct class for a cache bin. @@ -37,19 +37,0 @@ - * Deletes items from all bins with any of the specified tags. - * - * Many sites have more than one active cache backend, and each backend may use - * a different strategy for storing tags against cache items, and deleting cache - * items associated with a given tag. - * - * When deleting a given list of tags, we iterate over each cache backend, and - * and call deleteTags() on each. - * - * @param array $tags - * The list of tags to delete cache items for. - */ -function cache_delete_tags(array $tags) { - array_map(function (CacheBackendInterface $cache_backend) use ($tags) { - $cache_backend->deleteTags($tags); - }, cache_get_bins()); -} - -/** @@ -67,20 +49,5 @@ + * @deprecated */ function cache_invalidate_tags(array $tags) { - array_map(function (CacheBackendInterface $cache_backend) use ($tags) { - $cache_backend->invalidateTags($tags); - }, cache_get_bins()); -} - -/** - * @return array - * An array of cache backend objects keyed by cache bins. - */ -function cache_get_bins() { - $bins = array(); - $container = drupal_container(); - foreach ($container->getParameter('cache_bins') as $service_id => $bin) { - $bins[$bin] = $container->get($service_id); - } - return $bins; + Cache::invalidateTags($tags); } - diff -u b/core/includes/common.inc b/core/includes/common.inc --- b/core/includes/common.inc +++ b/core/includes/common.inc @@ -1,5 +1,6 @@ deleteAll(); - }, cache_get_bins()); + }, CacheHelper::getBins()); */ - foreach (cache_get_bins() as $bin => $cache_backend) { + foreach (Cache::getBins() as $bin => $cache_backend) { if ($bin != 'form' && $bin != 'menu') { $cache_backend->deleteAll(); } diff -u b/core/includes/install.core.inc b/core/includes/install.core.inc --- b/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1626,13 +1626,7 @@ * @param $install_state * An array of information about the current installation state. */ -function install_bootstrap_full(&$install_state) { - // The early stages of the installer override the cache backend since Drupal - // isn't fully set up yet. Here the override is removed so that the standard - // cache backend will be used again. - unset($GLOBALS['conf']['cache_classes']['cache']); - drupal_static_reset('cache'); - +function install_bootstrap_full() { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); } diff -u b/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php --- b/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Cache; +use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; use Drupal\Core\Database\DatabaseException; @@ -34,10 +35,12 @@ /** * Constructs a DatabaseBackend object. * + * @param \Drupal\Core\Database\Connection $connection + * The database connection. * @param string $bin * The cache bin for which the object is created. */ - public function __construct($connection, $bin) { + public function __construct(Connection $connection, $bin) { // All cache tables should be prefixed with 'cache_', except for the // default 'cache' bin. if ($bin != 'cache') { reverted: --- b/core/lib/Drupal/Core/Cache/ListCacheBins.php +++ /dev/null @@ -1,30 +0,0 @@ -findTaggedServiceIds('cache.bin') as $id => $attributes) { - $cache_bins[$id] = substr($id, 6); - } - $container->setParameter('cache_bins', $cache_bins); - } -} diff -u b/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php --- b/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -7,6 +7,8 @@ namespace Drupal\Core; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\ListCacheBinsPass; use Drupal\Core\DependencyInjection\Compiler\RegisterKernelListenersPass; use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass; use Drupal\Core\DependencyInjection\Compiler\RegisterMatchersPass; @@ -39,12 +41,7 @@ // Register cache services. foreach (array('bootstrap', 'config', 'cache', 'form', 'menu', 'page', 'path') as $bin) { - $container - ->register("cache.$bin", 'Drupal\Core\Cache\CacheBackendInterface') - ->setFactoryService('cache_factory') - ->setFactoryMethod('get') - ->addArgument('bootstrap') - ->addTag('cache.bin'); + Cache::registerBin($container, $bin); } $container @@ -55,7 +52,9 @@ $container ->register('cache.backend.database', 'Drupal\Core\Cache\DatabaseBackendFactory') ->addArgument(new Reference('database')); - $container->addCompilerPass(new \Drupal\Core\Cache\ListCacheBins()); + $container + ->register('cache.backend.memory', 'Drupal\Core\Cache\MemoryBackendFactory'); + $container->addCompilerPass(new ListCacheBinsPass()); // Register active configuration storage. $container diff -u b/core/modules/block/lib/Drupal/block/BlockBundle.php b/core/modules/block/lib/Drupal/block/BlockBundle.php --- b/core/modules/block/lib/Drupal/block/BlockBundle.php +++ b/core/modules/block/lib/Drupal/block/BlockBundle.php @@ -7,6 +7,7 @@ namespace Drupal\Block; +use Drupal\Core\Cache\Cache; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -22,12 +23,7 @@ // Register the BlockManager class with the dependency injection container. $container->register('plugin.manager.block', 'Drupal\block\Plugin\Type\BlockManager') ->addArgument('%container.namespaces%'); - $container - ->register('cache.block', 'Drupal\Core\Cache\CacheBackendInterface') - ->setFactoryService('cache_factory') - ->setFactoryMethod('get') - ->addArgument('block') - ->addTag('cache.bin'); + Cache::registerBin($container, 'block'); } } diff -u b/core/modules/field/lib/Drupal/field/FieldBundle.php b/core/modules/field/lib/Drupal/field/FieldBundle.php --- b/core/modules/field/lib/Drupal/field/FieldBundle.php +++ b/core/modules/field/lib/Drupal/field/FieldBundle.php @@ -7,6 +7,7 @@ namespace Drupal\field; +use Drupal\Core\Cache\Cache; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -24,12 +25,7 @@ ->addArgument('%container.namespaces%'); $container->register('plugin.manager.field.formatter', 'Drupal\field\Plugin\Type\Formatter\FormatterPluginManager') ->addArgument('%container.namespaces%'); - $container - ->register("cache.field", 'Drupal\Core\Cache\CacheBackendInterface') - ->setFactoryService('cache_factory') - ->setFactoryMethod('get') - ->addArgument('field') - ->addTag('cache.bin'); + Cache::registerBin($container, 'field'); } } diff -u b/core/modules/filter/lib/Drupal/filter/FilterBundle.php b/core/modules/filter/lib/Drupal/filter/FilterBundle.php --- b/core/modules/filter/lib/Drupal/filter/FilterBundle.php +++ b/core/modules/filter/lib/Drupal/filter/FilterBundle.php @@ -7,11 +7,12 @@ namespace Drupal\filter; +use Drupal\Core\Cache\Cache; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * Filter dependency injection container. + * Registers filter module's services to the container. */ class FilterBundle extends Bundle { @@ -19,12 +20,7 @@ * Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build(). */ public function build(ContainerBuilder $container) { - $container - ->register("cache.filter", 'Drupal\Core\Cache\CacheBackendInterface') - ->setFactoryService('cache_factory') - ->setFactoryMethod('get') - ->addArgument('filter') - ->addTag('cache.bin'); + Cache::registerBin($container, 'filter'); } } diff -u b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\simpletest; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DrupalKernel; use Drupal\Core\KeyValueStore\KeyValueMemoryFactory; use Symfony\Component\DependencyInjection\Reference; @@ -90,7 +91,6 @@ $this->containerBuild(drupal_container()); // Make sure it survives kernel rebuilds. $GLOBALS['conf']['container_bundles'][] = 'Drupal\simpletest\TestBundle'; - $GLOBALS['conf']['container_bundles']['simpletest_install_bundle'] = 'Drupal\simpletest\InstallBundle'; state()->set('system.module.files', $this->moduleFiles); state()->set('system.theme.files', $this->themeFiles); @@ -140,12 +140,13 @@ * @see DrupalUnitTestBase::enableModules() * @see DrupalUnitTestBase::disableModules() */ - public function containerBuild($container) { + public function containerBuild(ContainerBuilder $container) { global $conf; // Keep the container object around for tests. $this->container = $container; $container->register('lock', 'Drupal\Core\Lock\NullLockBackend'); + $this->settingsSet('cache', array('default' => 'cache.backend.memory')); $container ->register('config.storage', 'Drupal\Core\Config\FileStorage') reverted: --- b/core/modules/simpletest/lib/Drupal/simpletest/InstallBundle.php +++ /dev/null @@ -1,26 +0,0 @@ -register("cache.$bin", 'Drupal\Core\Cache\MemoryBackend') - ->addArgument($bin); - } - } - -} diff -u b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -806,10 +806,9 @@ $GLOBALS['conf']['file_public_path'] = $this->public_files_directory; // Execute the non-interactive installer. require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; - $GLOBALS['conf']['container_bundles']['simpletest_install_bundle'] = 'Drupal\simpletest\InstallBundle'; + $this->settingsSet('cache', array('default' => 'cache.backend.memory')); install_drupal($settings); $this->rebuildContainer(); - unset($GLOBALS['conf']['container_bundles']['simpletest_install_bundle']); // Restore the original Simpletest batch. $batch = &batch_get(); diff -u b/core/modules/system/lib/Drupal/system/Tests/Cache/ClearTest.php b/core/modules/system/lib/Drupal/system/Tests/Cache/ClearTest.php --- b/core/modules/system/lib/Drupal/system/Tests/Cache/ClearTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Cache/ClearTest.php @@ -10,6 +10,8 @@ /** * Tests cache clearing methods. */ +use Drupal\Core\Cache\Cache; + class ClearTest extends CacheTestBase { public static function getInfo() { @@ -32,7 +34,9 @@ */ function testFlushAllCaches() { // Create cache entries for each flushed cache bin. - $bins = cache_get_bins(); + $bins = Cache::getBins(); + // @todo remove after http://drupal.org/node/512026 + unset($bins['form']); foreach ($bins as $bin => $service) { if (!$service instanceof \Drupal\Core\Cache\CacheBackendInterface) { $this->fail(format_string('@bin is not a valid cache backend', array('@in' => $bin))); diff -u b/core/modules/system/system.module b/core/modules/system/system.module --- b/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Database; use Drupal\Core\Utility\ModuleInfo; use Drupal\Core\TypedData\Primitive; @@ -3525,7 +3526,7 @@ module_invoke_all('cache_flush'); array_map(function (CacheBackendInterface $cache_backend) { $cache_backend->deleteExpired(); - }, cache_get_bins()); + }, Cache::getBins()); // Cleanup the batch table and the queue for failed batches. db_delete('batch') diff -u b/core/modules/toolbar/lib/Drupal/toolbar/ToolbarBundle.php b/core/modules/toolbar/lib/Drupal/toolbar/ToolbarBundle.php --- b/core/modules/toolbar/lib/Drupal/toolbar/ToolbarBundle.php +++ b/core/modules/toolbar/lib/Drupal/toolbar/ToolbarBundle.php @@ -7,11 +7,12 @@ namespace Drupal\toolbar; +use Drupal\Core\Cache\Cache; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * Toolbar dependency injection container. + * Registers toolbar module's services to the container. */ class ToolbarBundle extends Bundle { @@ -19,12 +20,7 @@ * Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build(). */ public function build(ContainerBuilder $container) { - $container - ->register("cache.toolbar", 'Drupal\Core\Cache\CacheBackendInterface') - ->setFactoryService('cache_factory') - ->setFactoryMethod('get') - ->addArgument('toolbar') - ->addTag('cache.bin'); + Cache::registerBin($container, 'toolbar'); } } diff -u b/core/modules/views/lib/Drupal/views/ViewsBundle.php b/core/modules/views/lib/Drupal/views/ViewsBundle.php --- b/core/modules/views/lib/Drupal/views/ViewsBundle.php +++ b/core/modules/views/lib/Drupal/views/ViewsBundle.php @@ -7,6 +7,7 @@ namespace Drupal\views; +use Drupal\Core\Cache\Cache; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\Reference; @@ -36,18 +37,8 @@ $container->register('views.analyzer', 'Drupal\views\Analyzer') ->addArgument(new Reference('module_handler')); - $container - ->register("cache.views_info", 'Drupal\Core\Cache\CacheBackendInterface') - ->setFactoryService('cache_factory') - ->setFactoryMethod('get') - ->addArgument('views_info') - ->addTag('cache.bin'); - $container - ->register("cache.views_results", 'Drupal\Core\Cache\CacheBackendInterface') - ->setFactoryService('cache_factory') - ->setFactoryMethod('get') - ->addArgument('views_results') - ->addTag('cache.bin'); + Cache::registerBin($container, 'views_info'); + Cache::registerBin($container, 'views_results'); } } diff -u b/core/modules/views/views.module b/core/modules/views/views.module --- b/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -9,6 +9,7 @@ * incoming page and block requests. */ +use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Query\AlterableInterface; use Drupal\views\ViewExecutable; use Drupal\Component\Plugin\Exception\PluginException; @@ -680,7 +681,7 @@ cache('views_info')->deleteAll(); // Clear the page and block cache. - cache_delete_tags(array('content' => TRUE)); + Cache::deleteTags(array('content' => TRUE)); // Set the menu as needed to be rebuilt. state()->set('menu_rebuild_needed', TRUE); only in patch2: unchanged: --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -9,6 +9,7 @@ */ use Drupal\Component\Graph\Graph; +use Drupal\Component\Utility\Settings; use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\ConfigException; use Drupal\Core\DrupalKernel; @@ -97,7 +98,9 @@ function update_prepare_d8_bootstrap() { // During the bootstrap to DRUPAL_BOOTSTRAP_PAGE_CACHE, code will try to read // the cache but the cache tables are not compatible yet. Use the Null backend // by default to avoid exceptions. - $GLOBALS['conf']['cache_classes'] = array('cache' => 'Drupal\Core\Cache\NullBackend'); + $settings = settings()->getAll(); + $settings['cache']['default'] = 'cache.backend.memory'; + new Settings($settings); // Enable UpdateBundle service overrides. $GLOBALS['conf']['container_bundles'][] = 'Drupal\Core\DependencyInjection\UpdateBundle'; @@ -434,8 +437,11 @@ function update_prepare_d8_bootstrap() { } } // Now remove the cache override. - unset($GLOBALS['conf']['cache_classes']['cache']); - drupal_static_reset('cache'); + $settings = settings()->getAll(); + unset($settings['cache']['default']); + new Settings($settings); + $kernel = new DrupalKernel('update', FALSE, drupal_classloader(), FALSE); + $kernel->boot(); } /** only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Cache/Cache.php @@ -0,0 +1,84 @@ +register("cache.$bin", 'Drupal\Core\Cache\CacheBackendInterface') + ->setFactoryService('cache_factory') + ->setFactoryMethod('get') + ->addArgument($bin) + ->addTag('cache.bin'); + } + + /** + * Deletes items from all bins with any of the specified tags. + * + * Many sites have more than one active cache backend, and each backend may + * use a different strategy for storing tags against cache items, and + * deleting cache items associated with a given tag. + * + * When deleting a given list of tags, we iterate over each cache backend, and + * and call deleteTags() on each. + * + * @param array $tags + * The list of tags to delete cache items for. + */ + static function deleteTags(array $tags) { + array_map(function (CacheBackendInterface $cache_backend) use ($tags) { + $cache_backend->deleteTags($tags); + }, static::getBins()); + } + + /** + * Marks cache items from all bins with any of the specified tags as invalid. + * + * Many sites have more than one active cache backend, and each backend my use + * a different strategy for storing tags against cache items, and invalidating + * cache items associated with a given tag. + * + * When invalidating a given list of tags, we iterate over each cache backend, + * and call invalidateTags() on each. + * + * @param array $tags + * The list of tags to invalidate cache items for. + */ + static function invalidateTags(array $tags) { + array_map(function (CacheBackendInterface $cache_backend) use ($tags) { + $cache_backend->invalidateTags($tags); + }, static::getBins()); + } + + /** + * Gets all cache bin services. + * + * @return array + * An array of cache backend objects keyed by cache bins. + */ + static function getBins() { + $bins = array(); + $container = drupal_container(); + foreach ($container->getParameter('cache_bins') as $service_id => $bin) { + $bins[$bin] = $container->get($service_id); + } + return $bins; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Cache/ListCacheBinsPass.php @@ -0,0 +1,30 @@ +findTaggedServiceIds('cache.bin') as $id => $attributes) { + $cache_bins[$id] = substr($id, strpos($id, '.') + 1); + } + $container->setParameter('cache_bins', $cache_bins); + } +} only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php @@ -0,0 +1,16 @@ +deleteAll(); + if (module_exists('update')) { + _update_cache_clear(); } update_task_list('info');