Skip to content

Commit

Permalink
only call serialize once for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Apr 7, 2019
1 parent 7b64d88 commit ea4f387
Showing 1 changed file with 9 additions and 3 deletions.
Expand Up @@ -371,7 +371,9 @@ private function isMaxDepthReached(array $attributesMetadata, $class, $attribute
}

/**
* Overwrite to update the cache key for the child.
* Overwritten to update the cache key for the child.
*
* We must not mix up the attribute cache between parent and children.
*
* {@inheritdoc}
*/
Expand All @@ -385,7 +387,7 @@ protected function createChildContext(array $parentContext, $attribute)
}

/**
* Build the cache key for the attributes cache.
* Builds the cache key for the attributes cache.
*
* The key must be different for every option in the context that could change which attributes should be handled.
*
Expand All @@ -397,7 +399,11 @@ protected function createChildContext(array $parentContext, $attribute)
private function getAttributeCacheKey($format, array $context)
{
try {
return md5($format.serialize($context).serialize($this->ignoredAttributes)).serialize($this->camelizedAttributes);
return md5($format.serialize([
'context' => $context,
'ignored' => $this->ignoredAttributes,
'camelized' => $this->camelizedAttributes,
]));
} catch (\Exception $exception) {
// The context cannot be serialized, skip the cache
return false;
Expand Down

0 comments on commit ea4f387

Please sign in to comment.