1212 */
1313class Builder implements \Magento \Framework \View \Model \PageLayout \Config \BuilderInterface
1414{
15+ const CACHE_KEY_LAYOUTS = 'THEME_LAYOUTS_FILES_MERGED ' ;
16+
1517 /**
1618 * @var \Magento\Framework\View\PageLayout\ConfigFactory
1719 */
@@ -32,19 +34,27 @@ class Builder implements \Magento\Framework\View\Model\PageLayout\Config\Builder
3234 */
3335 private $ configFiles = [];
3436
37+ /**
38+ * @var \Magento\Framework\App\Cache\Type\Layout
39+ */
40+ protected $ cacheModel ;
41+
3542 /**
3643 * @param \Magento\Framework\View\PageLayout\ConfigFactory $configFactory
3744 * @param \Magento\Framework\View\PageLayout\File\Collector\Aggregated $fileCollector
3845 * @param \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection
46+ * @param \Magento\Framework\App\Cache\Type\Layout $cacheModel
3947 */
4048 public function __construct (
4149 \Magento \Framework \View \PageLayout \ConfigFactory $ configFactory ,
4250 \Magento \Framework \View \PageLayout \File \Collector \Aggregated $ fileCollector ,
43- \Magento \Theme \Model \ResourceModel \Theme \Collection $ themeCollection
51+ \Magento \Theme \Model \ResourceModel \Theme \Collection $ themeCollection ,
52+ \Magento \Framework \App \Cache \Type \Layout $ cacheModel
4453 ) {
4554 $ this ->configFactory = $ configFactory ;
4655 $ this ->fileCollector = $ fileCollector ;
4756 $ this ->themeCollection = $ themeCollection ;
57+ $ this ->cacheModel = $ cacheModel ;
4858 $ this ->themeCollection ->setItemObjectClass (\Magento \Theme \Model \Theme \Data::class);
4959 }
5060
@@ -57,18 +67,25 @@ public function getPageLayoutsConfig()
5767 }
5868
5969 /**
60- * Retrieve configuration files.
70+ * Retrieve configuration files. Caches merged layouts.xml XML files.
6171 *
6272 * @return array
6373 */
6474 protected function getConfigFiles ()
6575 {
6676 if (!$ this ->configFiles ) {
6777 $ configFiles = [];
68- foreach ($ this ->themeCollection ->loadRegisteredThemes () as $ theme ) {
69- $ configFiles [] = $ this ->fileCollector ->getFilesContent ($ theme , 'layouts.xml ' );
78+ $ this ->configFiles = $ this ->cacheModel ->load (self ::CACHE_KEY_LAYOUTS );
79+ if (!empty ($ this ->configFiles )) {
80+ $ this ->configFiles = @unserialize ($ this ->configFiles );//if value in cache is corrupted.
81+ }
82+ if (empty ($ this ->configFiles )) {
83+ foreach ($ this ->themeCollection ->loadRegisteredThemes () as $ theme ) {
84+ $ configFiles [] = $ this ->fileCollector ->getFilesContent ($ theme , 'layouts.xml ' );
85+ }
86+ $ this ->configFiles = array_merge (...$ configFiles );
87+ $ this ->cacheModel ->save (serialize ($ this ->configFiles ), self ::CACHE_KEY_LAYOUTS );
7088 }
71- $ this ->configFiles = array_merge (...$ configFiles );
7289 }
7390
7491 return $ this ->configFiles ;
0 commit comments