Closed
Description
Symfony version(s) affected: I'm on 4.4.1 but surely may be all versions
Description
In prod mode, the system cache is a chain [phpArray, apcu]. This is given to CacheClassMetadataFactory that does the job to cache the computed data across each requests.
On an API Platform, I got this stacktrace tht calls CacheClassMetadataFactory:
#0 /var/www/project/apps/api/vendor/symfony/cache/Adapter/ChainAdapter.php(124): Symfony\Component\Cache\Adapter\AbstractAdapter->getItem('Lib_Core_Entity...')
#1 /var/www/project/apps/api/vendor/symfony/cache/Adapter/PhpArrayAdapter.php(127): Symfony\Component\Cache\Adapter\ChainAdapter->getItem('Lib_Core_Entity...')
#2 /var/www/project/apps/api/vendor/symfony/serializer/Mapping/Factory/CacheClassMetadataFactory.php(54): Symfony\Component\Cache\Adapter\PhpArrayAdapter->getItem('Lib_Core_Entity...')
#3 /var/www/project/apps/api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php(166): Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory->getMetadataFor('Lib\\Core\\Entity...')
#4 /var/www/project/apps/api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php(151): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->normalize(Object(Lib\Core\Entity\Site), 'json', Array)
#5 /var/www/project/apps/api/vendor/symfony/serializer/Serializer.php(152): ApiPlatform\Core\Serializer\AbstractItemNormalizer->normalize(Object(Lib\Core\Entity\Site), 'json', Array)
The same calls is made a few hundred times. Each hitting apcu.
A very simple local cache clears everything:
How to reproduce
basic apip and symfony with last versions and apcu available. But should be reproducible with any use of AbstractObjectNormalizer.php.
Possible Solution
I'm not sure about the correct fixe:
- a simple local cache
- inject another chain cache containing a simple array specifially to this cache, as it has no chance to change in prod mode.
- inject an array adapter in system cache, but seems more dangerous ([FrameworkBundle] Allow creating chained cache pools by providing several adapters #32294 (comment))
- phparray should have it precalculated?
- fix it in userland (symfony/serializer/Normalizer/AbstractObjectNormalizer.php)
- did I missed something?