From 0a9f203b7a4feb4cf0a9885d8188b25a068baba2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Nov 2026 14:08:13 +0100 Subject: [PATCH] perf(symfony): remove redundant property info cache files --- src/Symfony/Bundle/Resources/config/api.php | 3 ++- .../Resources/config/symfony/symfony.php | 2 +- .../ApiPlatformExtensionTest.php | 22 ++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/Resources/config/api.php b/src/Symfony/Bundle/Resources/config/api.php index 91f8ce1d406..3f4ab046ab6 100644 --- a/src/Symfony/Bundle/Resources/config/api.php +++ b/src/Symfony/Bundle/Resources/config/api.php @@ -50,6 +50,7 @@ use phpDocumentor\Reflection\DocBlockFactory; use phpDocumentor\Reflection\Types\ContextFactory; use PHPStan\PhpDocParser\Parser\PhpDocParser; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; @@ -107,7 +108,7 @@ ->decorate('api_platform.property_info') ->args([ service('.inner'), - service('cache.property_info'), + inline_service(ArrayAdapter::class), ]); $services->set('api_platform.negotiator', Negotiator::class); diff --git a/src/Symfony/Bundle/Resources/config/symfony/symfony.php b/src/Symfony/Bundle/Resources/config/symfony/symfony.php index 622bbd03a75..d5368a73617 100644 --- a/src/Symfony/Bundle/Resources/config/symfony/symfony.php +++ b/src/Symfony/Bundle/Resources/config/symfony/symfony.php @@ -30,7 +30,7 @@ $services->set('api_platform.cache_warmer.cache_pool_clearer', CachePoolClearerCacheWarmer::class) ->args([ service('cache.system_clearer'), - ['api_platform.cache.metadata.property', 'api_platform.cache.metadata.resource', 'api_platform.cache.metadata.resource_collection', 'api_platform.cache.metadata.operation', 'api_platform.cache.route_name_resolver', 'api_platform.cache.identifiers_extractor', 'api_platform.elasticsearch.cache.metadata.document', 'cache.property_info'], + ['api_platform.cache.metadata.property', 'api_platform.cache.metadata.resource', 'api_platform.cache.metadata.resource_collection', 'api_platform.cache.metadata.operation', 'api_platform.cache.route_name_resolver', 'api_platform.cache.identifiers_extractor', 'api_platform.elasticsearch.cache.metadata.document'], ]) ->tag('kernel.cache_warmer', ['priority' => 64]); }; diff --git a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 8f80ae8e788..dccaa78a427 100644 --- a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -36,8 +36,10 @@ use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand; use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\TwigBundle\TwigBundle; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\ObjectMapper\ObjectMapper; @@ -575,10 +577,20 @@ public function testPropertyInfoExtractorsDoNotLeakIntoFrameworkPropertyInfo(): } } - /** - * @see https://github.com/api-platform/core/issues/8332 - */ - public function testCachePoolClearerClearsPropertyInfoAndOperationMetadataCaches(): void + public function testPropertyInfoUsesInMemoryCache(): void + { + (new ApiPlatformExtension())->load(self::DEFAULT_CONFIG, $this->container); + + $propertyInfoCache = $this->container->getDefinition('api_platform.property_info.cache'); + $cachePool = $propertyInfoCache->getArgument(1); + + $this->assertInstanceOf(Definition::class, $cachePool); + $this->assertSame(ArrayAdapter::class, $cachePool->getClass()); + $this->assertContainerHasService('api_platform.metadata.property.metadata_factory.cached'); + $this->assertContainerHasService('api_platform.metadata.property.name_collection_factory.cached'); + } + + public function testCachePoolClearerClearsOperationMetadataCache(): void { $this->container->setParameter('kernel.debug', true); $config = self::DEFAULT_CONFIG; @@ -586,7 +598,7 @@ public function testCachePoolClearerClearsPropertyInfoAndOperationMetadataCaches $this->assertContainerHasService('api_platform.cache_warmer.cache_pool_clearer'); $pools = $this->container->getDefinition('api_platform.cache_warmer.cache_pool_clearer')->getArgument(1); - $this->assertContains('cache.property_info', $pools); + $this->assertNotContains('cache.property_info', $pools); $this->assertContains('api_platform.cache.metadata.operation', $pools); }