|
5 | 5 | */ |
6 | 6 | namespace Magento\Framework\App\Router; |
7 | 7 |
|
| 8 | +use Magento\Framework\App\Filesystem\DirectoryList; |
| 9 | +use Magento\Framework\App\State; |
8 | 10 | use Magento\Framework\Serialize\SerializerInterface; |
9 | 11 | use Magento\Framework\Serialize\Serializer\Serialize; |
10 | 12 | use Magento\Framework\Module\Dir\Reader as ModuleReader; |
@@ -70,12 +72,26 @@ public function __construct( |
70 | 72 | $this->reservedWords = array_merge($reservedWords, $this->reservedWords); |
71 | 73 | $this->actionInterface = $actionInterface; |
72 | 74 | $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Serialize::class); |
73 | | - $data = $cache->load($cacheKey); |
74 | | - if (!$data) { |
75 | | - $this->actions = $moduleReader->getActionFiles(); |
76 | | - $cache->save($this->serializer->serialize($this->actions), $cacheKey); |
| 75 | + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); |
| 76 | + $state = $objectManager->get(State::class); |
| 77 | + |
| 78 | + if ($state->getMode() === State::MODE_PRODUCTION) { |
| 79 | + $directoryList = $objectManager->get(DirectoryList::class); |
| 80 | + $file = $directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheKey . '.' . 'php'; |
| 81 | + |
| 82 | + if (file_exists($file)) { |
| 83 | + $this->actions = (include $file) ?? $moduleReader->getActionFiles(); |
| 84 | + } else { |
| 85 | + $this->actions = $moduleReader->getActionFiles(); |
| 86 | + } |
77 | 87 | } else { |
78 | | - $this->actions = $this->serializer->unserialize($data); |
| 88 | + $data = $cache->load($cacheKey); |
| 89 | + if (!$data) { |
| 90 | + $this->actions = $moduleReader->getActionFiles(); |
| 91 | + $cache->save($this->serializer->serialize($this->actions), $cacheKey); |
| 92 | + } else { |
| 93 | + $this->actions = $this->serializer->unserialize($data); |
| 94 | + } |
79 | 95 | } |
80 | 96 | } |
81 | 97 |
|
|
0 commit comments