@@ -43,7 +43,10 @@ public function supportsNormalization($data, $format = null)
4343 */
4444 public function normalize ($ object , $ format = null , array $ context = [])
4545 {
46- $ context ['cache_key ' ] = $ this ->getHalCacheKey ($ format , $ context );
46+ if (!isset ($ context ['cache_key ' ])) {
47+ $ context ['cache_key ' ] = $ this ->getHalCacheKey ($ format , $ context );
48+ }
49+
4750 $ resourceClass = $ this ->resourceClassResolver ->getResourceClass ($ object , $ context ['resource_class ' ] ?? null , true );
4851 $ context = $ this ->initContext ($ resourceClass , $ context );
4952 $ context ['iri ' ] = $ this ->iriConverter ->getIriFromItem ($ object );
@@ -99,8 +102,10 @@ protected function getAttributes($object, $format = null, array $context)
99102 */
100103 private function getComponents ($ object , string $ format = null , array $ context )
101104 {
102- if (false !== $ context ['cache_key ' ] && isset ($ this ->componentsCache [$ context ['cache_key ' ]])) {
103- return $ this ->componentsCache [$ context ['cache_key ' ]];
105+ $ cacheKey = \get_class ($ object ).'- ' .$ context ['cache_key ' ];
106+
107+ if (isset ($ this ->componentsCache [$ cacheKey ])) {
108+ return $ this ->componentsCache [$ cacheKey ];
104109 }
105110
106111 $ attributes = parent ::getAttributes ($ object , $ format , $ context );
@@ -142,7 +147,7 @@ private function getComponents($object, string $format = null, array $context)
142147 }
143148
144149 if (false !== $ context ['cache_key ' ]) {
145- $ this ->componentsCache [$ context [ ' cache_key ' ] ] = $ components ;
150+ $ this ->componentsCache [$ cacheKey ] = $ components ;
146151 }
147152
148153 return $ components ;
0 commit comments