@@ -36,6 +36,11 @@ class ProductStorageDataMapper implements ProductStorageDataMapperInterface
3636 */
3737 protected $ localeClient ;
3838
39+ /**
40+ * @var array<string, \Generated\Shared\Transfer\ProductViewTransfer>
41+ */
42+ protected static array $ mappingCache = [];
43+
3944 /**
4045 * @uses \Spryker\Client\ProductStorage\Mapper\ProductStorageDataMapper::filterProductStorageExpanderPlugins()
4146 *
@@ -67,6 +72,12 @@ public function mapProductStorageData(
6772 array $ selectedAttributes = [],
6873 ?ProductStorageCriteriaTransfer $ productStorageCriteriaTransfer = null
6974 ) {
75+ $ cacheKey = $ this ->generateCacheKey ($ locale , $ productStorageData , $ selectedAttributes , $ productStorageCriteriaTransfer );
76+
77+ if (isset (static ::$ mappingCache [$ cacheKey ])) {
78+ return static ::$ mappingCache [$ cacheKey ];
79+ }
80+
7081 $ productStorageData = $ this ->filterAbstractProductVariantsData ($ productStorageData );
7182 $ productViewTransfer = $ this ->createProductViewTransfer ($ productStorageData );
7283 $ productViewTransfer ->setSelectedAttributes ($ selectedAttributes );
@@ -81,9 +92,29 @@ public function mapProductStorageData(
8192 $ productViewTransfer = $ productViewExpanderPlugin ->expandProductViewTransfer ($ productViewTransfer , $ productStorageData , $ locale );
8293 }
8394
95+ static ::$ mappingCache [$ cacheKey ] = $ productViewTransfer ;
96+
8497 return $ productViewTransfer ;
8598 }
8699
100+ protected function generateCacheKey (
101+ string $ locale ,
102+ array $ productStorageData ,
103+ array $ selectedAttributes ,
104+ ?ProductStorageCriteriaTransfer $ productStorageCriteriaTransfer
105+ ): string {
106+ $ criteriaKey = $ productStorageCriteriaTransfer !== null
107+ ? serialize ($ productStorageCriteriaTransfer ->toArray ())
108+ : 'null ' ;
109+
110+ return md5 (
111+ $ locale
112+ . serialize ($ productStorageData )
113+ . serialize ($ selectedAttributes )
114+ . $ criteriaKey ,
115+ );
116+ }
117+
87118 protected function filterAbstractProductVariantsData (array $ productStorageData ): array
88119 {
89120 return $ this ->productAbstractVariantsRestrictionFilter ->filterAbstractProductVariantsData ($ productStorageData );
0 commit comments