@@ -23,6 +23,16 @@ class CachedContentTypeLoader implements ContentTypeLoader
23
23
*/
24
24
private $ loadedItems = [];
25
25
26
+ /**
27
+ * @var array
28
+ */
29
+ private $ identifierToIdMap = [];
30
+
31
+ /**
32
+ * @var ContentType[]
33
+ */
34
+ private $ loadedItemsByIdentifier = [];
35
+
26
36
public function __construct (ContentTypeLoader $ innerLoader )
27
37
{
28
38
$ this ->innerLoader = $ innerLoader ;
@@ -31,20 +41,23 @@ public function __construct(ContentTypeLoader $innerLoader)
31
41
public function load ($ contentTypeId ): ContentType
32
42
{
33
43
if (!isset ($ this ->loadedItems [$ contentTypeId ])) {
34
- $ this ->loadedItems [$ contentTypeId ] = $ this ->innerLoader ->load ($ contentTypeId );
44
+ $ contentType = $ this ->innerLoader ->load ($ contentTypeId );
45
+ $ this ->loadedItems [$ contentTypeId ] = $ contentType ;
46
+ $ this ->identifierToIdMap [$ contentType ->identifier ] = $ contentTypeId ;
35
47
}
36
48
37
49
return $ this ->loadedItems [$ contentTypeId ];
38
50
}
39
51
40
52
public function loadByIdentifier ($ identifier ): ContentType
41
53
{
42
- $ contentType = $ this ->innerLoader -> loadByIdentifier ( $ identifier);
43
-
44
- if (! isset ( $ this ->innerLoader [$ contentType ->id ])) {
45
- $ this ->innerLoader [ $ contentType -> id ] = $ contentType ;
54
+ if (! isset ( $ this ->identifierToIdMap [ $ identifier])) {
55
+ $ contentType = $ this -> innerLoader -> loadByIdentifier ( $ identifier );
56
+ $ this ->loadedItems [$ contentType ->id ] = $ contentType ;
57
+ $ this ->identifierToIdMap [ $ identifier ] = $ contentType-> id ;
46
58
}
47
59
48
- return $ contentType ;
60
+
61
+ return $ this ->loadedItems [$ this ->identifierToIdMap [$ identifier ]];
49
62
}
50
63
}
0 commit comments