[僅限PaaS]{class="badge informative" title="僅適用於雲端專案(Adobe管理的PaaS基礎結構)和內部部署專案的Adobe Commerce 。"}
快取
您可以在雲端基礎結構專案環境中啟用快取。 如果停用快取,Adobe Commerce會直接提供檔案。
{default}預留位置代表為您的網站設定的預設網域。 如果您的專案有多個網域,請使用{all}預留位置來設定預設網域和所有別名的路由。 請參閱設定路由。設定快取
透過在.magento/routes.yaml檔案中設定快取規則來啟用應用程式的快取,如下所示:
http://{default}/:
type: upstream
upstream: php:php
cache:
enabled: true
headers: [ "Accept", "Accept-Language", "X-Language-Locale" ]
cookies: ["*"]
default_ttl: 60
路由型快取
為數個路由分別設定快取規則,以啟用微調快取,如下列範例所示:
http://{default}/:
type: upstream
upstream: php:php
cache:
enabled: true
http://{default}/path/:
type: upstream
upstream: php:php
cache:
enabled: false
http://{default}/path/more/:
type: upstream
upstream: php:php
cache:
enabled: true
上述範例快取下列路由:
http://{default}/http://{default}/path/more/http://{default}/path/more/etc/
而且下列路由是 不是 快取:
http://{default}/path/http://{default}/path/etc/
快取持續時間
快取期間由Cache-Control回應標頭值決定。 如果回應中沒有Cache-Control標頭,則會使用default_ttl金鑰。
快取金鑰
為決定如何快取回應,Adobe Commerce會根據數個因素建立快取金鑰,並儲存與此金鑰相關聯的回應。 當請求帶有相同的快取金鑰時,將重複使用回應。 其用途與HTTP Vary標頭類似。
引數headers和cookies金鑰可讓您變更此快取金鑰。
這些鍵的預設值如下:
cache:
enabled: true
headers: ["Accept-Language", "Accept"]
cookies: ["*"]
快取屬性
enabled
設定為true時,啟用此路由的快取。 設定為false時,停用此路由的快取。
headers
定義快取索引鍵必須相依的值。
例如,如果headers索引鍵如下:
cache:
enabled: true
headers: ["Accept"]
然後Adobe Commerce會為Accept HTTP標頭的每個值快取不同的回應。
cookies
cookies索引鍵定義快取索引鍵必須相依的值。
例如:
cache:
enabled: true
cookies: ["value"]
快取金鑰取決於要求中value Cookie的值。
如果cookies機碼具有["*"]值,則為特殊情況。 此值表示任何具有Cookie的請求都會繞過快取。 這是預設值。
*)的所有Cookie。 例如,SESS*或~SESS目前是 不是 個有效值。Cookie有下列限制:
- 系統中設定了最多 50 Cookie 個。 否則,應用程式會擲回
Unable to send the cookie. Maximum number of cookies would be exceeded例外狀況。 若要將Cookie數目增加到200,請使用品質修補程式工具套用MDVA-12304修補程式。 - Cookie大小上限為 4096位元組。 否則,應用程式會擲回
Unable to send the cookie. Size of '%name' is %size bytes例外狀況。
default_ttl
如果回應沒有Cache-Control標頭,則會使用default_ttl索引鍵來定義快取持續時間(以秒為單位)。 預設值為0,這表示不會快取任何內容。