10000 [FrameworkBundle] cache ClassMetadataFactory in debug by bastnic · Pull Request #35109 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] cache ClassMetadataFactory in debug #35109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <dunglas@gmail.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure I was the author 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you send a PR? :)

*
* @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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1457,10 +1457,6 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
$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']));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@
<service id="data_collector.cache" class="Symfony\Component\Cache\DataCollector\CacheDataCollector" public="true">
<tag name="data_collector" template="@WebProfiler/Collector/cache.html.twig" id="cache" priority="275" />
</service>

<!-- CacheWarmer used in dev to clear cache pool -->
<service id="cache_pool_clearer.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\CachePoolClearerCacheWarmer" public="false">
<argument type="service" id="cache.system_clearer" />
<argument type="collection">
<argument>cache.validator</argument>
<argument>cache.serializer</argument>
</argument>
<tag name="kernel.cache_warmer" priority="64" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,10 @@ public function testSerializerCacheActivated()
$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()
Expand Down
0