昨天我們追蹤了 Identifier.php
的程式碼,理解了 Magento 是怎麼產生 Redis key。
但光看一段程式碼還不夠,我們還需要把它放進整個 Request → Response 的流程裡,才能真正看懂快取是怎麼工作的。
今天就來分享:Magento 的 HTTP 請求流程,以及 Page Cache 插手的時機。
當使用者請求一個頁面,Magento 的流程大致是這樣:
index.php
所有 HTTP 請求的入口。
bootstrap.php
啟動 Magento 2。
http.php
進入 HTTP 請求處理的核心。
BuiltinPlugin.php (module-page-cache)
這裡會檢查 request 的 identifier 是否已存在快取。
Response
頁面立刻送回給使用者,超省效能 🚀。
Request 進來
使用者的 HTTP 請求經過 index.php
→ bootstrap.php
→ http.php
。
BuiltinPlugin.php 插手檢查
frontcontroller.php
Magento\Catalog\Controller\Category\View
。Magento 執行邏輯並產生 Response
BuiltinPlugin.php 再次插手
X-Magento-Tags
、Cache-Control
)。Response 回傳
也就是說,這裡的重點有兩個:
frontcontroller
前面),能大幅省下後端資源。現在我們把「快取在哪一步介入」講清楚了:
Magento 的 Full Page Cache 是在 HTTP request 一進來時就攔截,並根據 identifier 決定是否命中。
昨天我們知道 identifier 太敏感,會導致重複快取;
今天我們看到它實際影響整個流程。
👉 明天我們就要繼續挑戰:
能不能優化這些 identifier,避免 Redis 裡塞滿重複資料?