10000 [Serializer] Include the format in the cache key · symfony/symfony@282eb9c · GitHub
[go: up one dir, main page]

Skip to content

Commit 282eb9c

Browse files
dunglasfabpot
authored andcommitted
[Serializer] Include the format in the cache key
1 parent 414d9ef commit 282eb9c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function supportsNormalization($data, $format = null)
5656
public function normalize($object, $format = null, array $context = array())
5757
{
5858
if (!isset($context['cache_key'])) {
59-
$context['cache_key'] = $this->getCacheKey($context);
59+
$context['cache_key'] = $this->getCacheKey($format, $context);
6060
}
6161

6262
if ($this->isCircularReference($object, $context)) {
@@ -169,7 +169,7 @@ public function supportsDenormalization($data, $type, $format = null)
169169
public function denormalize($data, $class, $format = null, array $context = array())
170170
{
171171
if (!isset($context['cache_key'])) {
172-
$context['cache_key'] = $this->getCacheKey($context);
172+
$context['cache_key'] = $this->getCacheKey($format, $context);
173173
}
174174
$allowedAttributes = $this->getAllowedAttributes($class, $context, true);
175175
$normalizedData = $this->prepareForDenormalization($data);
@@ -336,14 +336,15 @@ private function isMaxDepthReached($class, $attribute, array &$context)
336336
/**
337337
* Gets the cache key to use.
338338
*
339-
* @param array $context
339+
* @param string|null $format
340+
* @param array $context
340341
*
341342
* @return bool|string
342343
*/
343-
private function getCacheKey(array $context)
344+
private function getCacheKey($format, array $context)
344345
{
345346
try {
346-
return md5(serialize($context));
347+
return md5($format.serialize($context));
347348
} catch (\Exception $exception) {
348349
// The context cannot be serialized, skip the cache
349350
return false;

0 commit comments

Comments
 (0)
0