diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/CachePoolClearerCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/CachePoolClearerCacheWarmer.php new file mode 100644 index 0000000000..988181b7f8 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/CachePoolClearerCacheWarmer.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; + +use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer; +use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; + +/** + * Clears the cache pools when warming up the cache. + * + * Do not use in production! + * + * @author Kévin Dunglas + * + * @internal + */ +final class CachePoolClearerCacheWarmer implements CacheWarmerInterface +{ + private $poolClearer; + private $pools; + + public function __construct(Psr6CacheClearer $poolClearer, array $pools = []) + { + $this->poolClearer = $poolClearer; + $this->pools = $pools; + } + + /** + * {@inheritdoc} + */ + public function warmUp($cacheDirectory): void + { + foreach ($this->pools as $pool) { + if ($this->poolClearer->hasPool($pool)) { + $this->poolClearer->clearPool($pool); + } + } + } + + /** + * {@inheritdoc} + */ + public function isOptional(): bool + { + // optional cache warmers are not run when handling the request + return false; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index aabd77c551..a8cb13a349 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1457,10 +1457,6 @@ class FrameworkExtension extends Extension $chainLoader->replaceArgument(0, $serializerLoaders); $container->getDefinition('serializer.mapping.cache_warmer')->replaceArgument(0, $serializerLoaders); - if ($container->getParameter('kernel.debug')) { - $container->removeDefinition('serializer.mapping.cache_class_metadata_factory'); - } - if (isset($config['name_converter']) && $config['name_converter']) { $container->getDefinition('serializer.name_converter.metadata_aware')->setArgument(1, new Reference($config['name_converter'])); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml index 20e22761a3..d4a7396c60 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml @@ -11,5 +11,15 @@ + + + + + + cache.validator + cache.serializer + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 6e6b5bd066..c84c49b5a8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1102,10 +1102,10 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEquals(new Reference('serializer.mapping.cache.symfony'), $cache); } - public function testSerializerCacheDisabled() + public function testSerializerCacheActivatedDebug() { $container = $this->createContainerFromFile('serializer_enabled', ['kernel.debug' => true, 'kernel.container_class' => __CLASS__]); - $this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory')); + $this->assertTrue($container->hasDefinition('serializer.mapping.cache_class_metadata_factory')); } public function testSerializerMapping()