@@ -43,7 +43,10 @@ public function supportsNormalization($data, $format = null)
43
43
*/
44
44
public function normalize ($ object , $ format = null , array $ context = [])
45
45
{
46
- $ context ['cache_key ' ] = $ this ->getHalCacheKey ($ format , $ context );
46
+ if (!isset ($ context ['cache_key ' ])) {
47
+ $ context ['cache_key ' ] = $ this ->getHalCacheKey ($ format , $ context );
48
+ }
49
+
47
50
$ resourceClass = $ this ->resourceClassResolver ->getResourceClass ($ object , $ context ['resource_class ' ] ?? null , true );
48
51
$ context = $ this ->initContext ($ resourceClass , $ context );
49
52
$ context ['iri ' ] = $ this ->iriConverter ->getIriFromItem ($ object );
@@ -99,8 +102,10 @@ protected function getAttributes($object, $format = null, array $context)
99
102
*/
100
103
private function getComponents ($ object , string $ format = null , array $ context )
101
104
{
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 ];
104
109
}
105
110
106
111
$ attributes = parent ::getAttributes ($ object , $ format , $ context );
@@ -142,7 +147,7 @@ private function getComponents($object, string $format = null, array $context)
142
147
}
143
148
144
149
if (false !== $ context ['cache_key ' ]) {
145
- $ this ->componentsCache [$ context [ ' cache_key ' ] ] = $ components ;
150
+ $ this ->componentsCache [$ cacheKey ] = $ components ;
146
151
}
147
152
148
153
return $ components ;
0 commit comments