Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4446b64

Browse files
committed
Remove static cache
1 parent 2ab3ad0 commit 4446b64

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
2626
*/
2727
private $fallbackNameConverter;
2828

29-
private static $normalizeCache = [];
29+
private $normalizeCache = [];
3030

31-
private static $denormalizeCache = [];
31+
private $denormalizeCache = [];
3232

33-
private static $attributesMetadataCache = [];
33+
private $attributesMetadataCache = [];
3434

3535
public function __construct(ClassMetadataFactoryInterface $metadataFactory, NameConverterInterface $fallbackNameConverter = null)
3636
{
@@ -47,11 +47,11 @@ public function normalize($propertyName, string $class = null, string $format =
4747
return $this->normalizeFallback($propertyName, $class, $format, $context);
4848
}
4949

50-
if (!isset(self::$normalizeCache[$class][$propertyName])) {
51-
self::$normalizeCache[$class][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
50+
if (!isset($this->normalizeCache[$class][$propertyName])) {
51+
$this->normalizeCache[$class][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
5252
}
5353

54-
return self::$normalizeCache[$class][$propertyName] ?? $this->normalizeFallback($propertyName, $class, $format, $context);
54+
return $this->normalizeCache[$class][$propertyName] ?? $this->normalizeFallback($propertyName, $class, $format, $context);
5555
}
5656

5757
/**
@@ -63,12 +63,11 @@ public function denormalize($propertyName, string $class = null, string $format
6363
return $this->denormalizeFallback($propertyName, $class, $format, $context);
6464
}
6565

66-
$cacheKey = $this->getCacheKey($propertyName, $context);
67-
if (!isset(self::$denormalizeCache[$class][$cacheKey])) {
68-
self::$denormalizeCache[$class][$cacheKey] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
66+
if (!isset($this->denormalizeCache[$class][$propertyName])) {
67+
$this->denormalizeCache[$class][$propertyName] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
6968
}
7069

71-
return self::$denormalizeCache[$class][$cacheKey] ?? $this->denormalizeFallback($propertyName, $class, $format, $context);
70+
return $this->denormalizeCache[$class][$propertyName] ?? $this->denormalizeFallback($propertyName, $class, $format, $context);
7271
}
7372

7473
private function getCacheValueForNormalization($propertyName, string $class)
@@ -92,11 +91,11 @@ private function normalizeFallback($propertyName, string $class = null, string $
9291

9392
private function getCacheValueForDenormalization($propertyName, string $class, $context)
9493
{
95-
if (!isset(self::$attributesMetadataCache[$class])) {
96-
self::$attributesMetadataCache[$class] = $this->getCacheValueForAttributesMetadata($class, $context);
94+
if (!isset($this->attributesMetadataCache[$class])) {
95+
$this->attributesMetadataCache[$class] = $this->getCacheValueForAttributesMetadata($class, $context);
9796
}
9897

99-
return self::$attributesMetadataCache[$class][$this->getCacheKey($propertyName, $context)] ?? null;
98+
return $this->attributesMetadataCache[$class][$propertyName] ?? null;
10099
}
101100

102101
private function denormalizeFallback($propertyName, string $class = null, string $format = null, array $context = [])
@@ -118,33 +117,17 @@ private function getCacheValueForAttributesMetadata(string $class, $context): ar
118117
continue;
119118
}
120119

121-
if (!($groups = $metadata->getGroups()) && ($context[AbstractNormalizer::GROUPS] ?? [])) {
120+
$groups = $metadata->getGroups();
121+
if (!$groups && ($context[AbstractNormalizer::GROUPS] ?? [])) {
122122
continue;
123123
}
124124
if ($groups && !array_intersect($groups, $context[AbstractNormalizer::GROUPS] ?? [])) {
125125
continue;
126126
}
127127

128-
129-
$cache[$this->getCacheKey($metadata->getSerializedName(), $context)] = $name;
128+
$cache[$metadata->getSerializedName()] = $name;
130129
}
131130

132131
return $cache;
133132
}
134-
135-
private function getCacheKey($propertyName, array $context): string
136-
{
137-
if (isset($context['cache_key'])) {
138-
return $propertyName.$context['cache_key'];
139-
}
140-
141-
try {
142-
$key = md5(serialize($context[AbstractNormalizer::GROUPS] ?? []));
143-
} catch (\Exception $e) {
144-
$key = '';
145-
} finally {
146-
return $propertyName.$key;
147-
}
148-
149-
}
150133
}

0 commit comments

Comments
 (0)