diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php b/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php index 0b904c14400d0..9f42d1ea21853 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php @@ -32,6 +32,8 @@ class CacheClassMetadataFactory implements ClassMetadataFactoryInterface */ private $cacheItemPool; + private $localCache = array(); + public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemPoolInterface $cacheItemPool) { $this->decorated = $decorated; @@ -47,15 +49,19 @@ public function getMetadataFor($value) // Key cannot contain backslashes according to PSR-6 $key = strtr($class, '\\', '_'); + if (array_key_exists($key, $this->localCache)) { + return $this->localCache[$key]; + } + $item = $this->cacheItemPool->getItem($key); if ($item->isHit()) { - return $item->get(); + return $this->localCache[$key] = $item->get(); } $metadata = $this->decorated->getMetadataFor($value); $this->cacheItemPool->save($item->set($metadata)); - return $metadata; + return $this->localCache[$key] = $metadata; } /**