設定靜態檔案的快取

您媒體和靜態檔案的快取TTL (存留時間)是使用expires索引鍵在.magento.app.yaml設定檔案中設定的。

NOTE
在更新生產環境之前,請務必在中繼環境中測試變更。 提交Adobe Commerce支援票證,以取得更新這些環境設定的協助。
  1. .magento.app.yaml檔案的web屬性中指定TTL時間(秒)。 您可以在locations底下或在"/media""/static"底下新增expires金鑰。

    若要防止快取到期,請使用expires: -1機碼值組。 請參閱下列範例:

    code language-yaml
    # The configuration of app when it is exposed to the web.
    web:
      locations:
        "/media":
          ...
          expires: -1
    
        "/static":
          ...
          expires: -1
    
  2. 新增、提交和推送您的程式碼變更。

    code language-bash
    git add -A && git commit -m "Set cache TTL for static files" && git push origin <branch-name>
    
recommendation-more-help
05f2f56e-ac5d-4931-8cdb-764e60e16f26