Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07b42d9

Browse filesBrowse files
committed
[FrameworkBundle] cache ClassMetadataFactory in debug
We already track modification in serialization/validator config directory so we just need to clear the cache at warmup. Idea taken from apip: https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/Bundle/CacheWarmer/CachePoolClearerCacheWarmer.php
1 parent 4e5b153 commit 07b42d9
Copy full SHA for 07b42d9

File tree

3 files changed

+58
-4
lines changed
Filter options

3 files changed

+58
-4
lines changed
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
4+
5+
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
6+
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
7+
8+
/**
9+
* Clears the cache pools when warming up the cache.
10+
*
11+
* Do not use in production!
12+
*
13+
* @author Kévin Dunglas <dunglas@gmail.com>
14+
*
15+
* @internal
16+
*/
17+
final class CachePoolClearerCacheWarmer implements CacheWarmerInterface
18+
{
19+
private $poolClearer;
20+
private $pools;
21+
22+
public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
23+
{
24+
$this->poolClearer = $poolClearer;
25+
$this->pools = $pools;
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function warmUp($cacheDirectory): void
32+
{
33+
foreach ($this->pools as $pool) {
34+
if ($this->poolClearer->hasPool($pool)) {
35+
$this->poolClearer->clearPool($pool);
36+
}
37+
}
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function isOptional(): bool
44+
{
45+
// optional cache warmers are not run when handling the request
46+
return false;
47+
}
48+
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,10 +1457,6 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
14571457
$chainLoader->replaceArgument(0, $serializerLoaders);
14581458
$container->getDefinition('serializer.mapping.cache_warmer')->replaceArgument(0, $serializerLoaders);
14591459

1460-
if ($container->getParameter('kernel.debug')) {
1461-
$container->removeDefinition('serializer.mapping.cache_class_metadata_factory');
1462-
}
1463-
14641460
if (isset($config['name_converter']) && $config['name_converter']) {
14651461
$container->getDefinition('serializer.name_converter.metadata_aware')->setArgument(1, new Reference($config['name_converter']));
14661462
}

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,15 @@
1111
<service id="data_collector.cache" class="Symfony\Component\Cache\DataCollector\CacheDataCollector" public="true">
1212
<tag name="data_collector" template="@WebProfiler/Collector/cache.html.twig" id="cache" priority="275" />
1313
</service>
14+
15+
<!-- CacheWarmer used in dev to clear cache pool -->
16+
<service id="cache_pool_clearer.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\CachePoolClearerCacheWarmer" public="false">
17+
<argument type="service" id="cache.system_clearer" />
18+
<argument type="collection">
19+
<argument>cache.validator</argument>
20+
<argument>cache.serializer</argument>
21+
</argument>
22+
<tag name="kernel.cache_warmer" priority="64" />
23+
</service>
1424
</services>
1525
</container>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.