例
Web ブラウザーと CDN キャッシュの HTML コンテンツタイプ の有効期間を、古い状態の処理を行わずに 10 分 に増やすには、次の手順に従います。
-
AEM プロジェクト内で、目的の vhost ファイルを
dispatcher/src/conf.d/available_vhosts
ディレクトリで見つけます。 -
その vhost(例:
wknd.vhost
)ファイルを次のように更新します。<LocationMatch "^/content/.*\.(html)$"> # Removes the response header if present Header unset Cache-Control # Instructs the web browser and CDN to cache the response for max-age value (600) seconds. Header set Cache-Control "max-age=600" </LocationMatch>
dispatcher/src/conf.d/enabled_vhosts
ディレクトリ内の vhost ファイルはdispatcher/src/conf.d/available_vhosts
ディレクトリ内のファイルへの シンボリックリンク なので、存在しない場合は、必ずシンボリックリンクを作成してください。 -
Cloud Manager - web 層設定パイプラインまたは RDE コマンドを使用して、目的の AEM as a Cloud Service 環境に vhost の変更をデプロイします。
ただし、web ブラウザーと CDN キャッシュの有効期間に異なる値を設定する場合は、Surrogate-Control
ヘッダーを使用します。同様に、キャッシュを特定の日時に期限切れにするには、Expires
ヘッダーを使用します。また、stale-while-revalidate
および stale-if-error
属性を指定すると、応答コンテンツの古い状態の処理を制御できます。AEM WKND プロジェクトには、古い状態の処理(参考例)の CDN キャッシュ設定が含まれています。
同様に、他のコンテンツタイプ(JSON、JS、CSS およびアセット)のキャッシュヘッダーも更新できます。
カスタム Java™ コード
このオプションは、AEM パブリッシュと AEM オーサーの両方で使用できます。ただし、AEM オーサーのキャッシュを有効にして、デフォルトのキャッシュ動作を維持することはお勧めしません。
キャッシュヘッダーを更新するには、カスタム Java™ コード(Sling サーブレット、Sling サーブレットフィルター)で HttpServletResponse
オブジェクトを使用します。一般的な構文は次のとおりです。
// Instructs the web browser and CDN to cache the response for 'max-age' value (XXX) seconds. The 'stale-while-revalidate' and 'stale-if-error' attributes controls the stale state treatment at CDN layer.
response.setHeader("Cache-Control", "max-age=XXX,stale-while-revalidate=XXX,stale-if-error=XXX");
// Instructs the CDN to cache the response for 'max-age' value (XXX) seconds. The 'stale-while-revalidate' and 'stale-if-error' attributes controls the stale state treatment at CDN layer.
response.setHeader("Surrogate-Control", "max-age=XXX,stale-while-revalidate=XXX,stale-if-error=XXX");
// Instructs the web browser and CDN to cache the response until the specified date and time.
response.setHeader("Expires", "Sun, 31 Dec 2023 23:59:59 GMT");