CDN 캐싱을 비활성화하는 방법
AEM as a Cloud Service CDN에서 HTTP 응답 캐싱을 비활성화하는 방법에 대해 알아봅니다. 응답 캐싱은 Cache-Control
, Surrogate-Control
또는 Expires
HTTP 응답 캐시 헤더에 의해 제어됩니다.
이러한 캐시 헤더는 일반적으로 mod_headers
을(를) 사용하여 AEM Dispatcher vhost 구성에서 설정되지만 AEM Publish 자체에서 실행되는 사용자 지정 Java™ 코드에서도 설정할 수 있습니다.
기본 캐싱 동작
AEM Project Archetype 기반 AEM 프로젝트가 배포되면 AEM Publish 및 작성자에 대한 기본 캐싱 동작을 검토하십시오.
캐싱 비활성화
캐싱을 해제하면 AEM as a Cloud Service 인스턴스의 성능에 부정적인 영향을 줄 수 있으므로 기본 캐싱 동작을 해제할 때 주의하십시오.
그러나 다음과 같이 캐싱을 비활성화할 수 있는 시나리오가 있습니다.
- 새 기능 개발 및 변경 사항을 즉시 확인하고자 합니다.
- 콘텐츠는 보안(인증된 사용자만 해당) 또는 동적(장바구니, 주문 세부 사항)이며 캐시되어서는 안 됩니다.
캐싱을 비활성화하려면 두 가지 방법으로 캐시 헤더를 업데이트할 수 있습니다.
- Dispatcher vhost 구성: AEM Publish에만 사용할 수 있습니다.
- 사용자 지정 Java™ 코드: AEM Publish과 작성자 모두에서 사용할 수 있습니다.
이러한 각 옵션을 검토해 보겠습니다.
Dispatcher vhost 구성
이 옵션은 캐싱을 비활성화하는 데 권장되는 접근 방식이지만 AEM Publish에만 사용할 수 있습니다. 캐시 헤더를 업데이트하려면 Apache HTTP Server의 vhost 파일에서 mod_headers
모듈 및 <LocationMatch>
지시문을 사용합니다. 일반 구문은 다음과 같습니다.
<LocationMatch "$URL$ || $URL_REGEX$">
# Removes the response header of this name, if it exists. If there are multiple headers of the same name, all will be removed.
Header unset Cache-Control
Header unset Expires
# Instructs the CDN to not cache the response.
Header set Cache-Control "private"
</LocationMatch>
예
일부 문제 해결 목적으로 CSS 콘텐츠 형식 의 CDN 캐싱을 비활성화하려면 다음 단계를 따르십시오.
기존 CSS 캐시를 무시하려면 CSS 파일에 대한 새 캐시 키를 생성하려면 CSS 파일을 변경해야 합니다.
-
AEM 프로젝트에서
dispatcher/src/conf.d/available_vhosts
디렉터리에서 원하는 가상 파일을 찾습니다. -
vhost(예:
wknd.vhost
) 파일을 다음과 같이 업데이트합니다.code language-none <LocationMatch "^/etc.clientlibs/.*\.(css)$"> # Removes the response header of this name, if it exists. If there are multiple headers of the same name, all will be removed. Header unset Cache-Control Header unset Expires # Instructs the CDN to not cache the response. Header set Cache-Control "private" </LocationMatch>
dispatcher/src/conf.d/enabled_vhosts
디렉터리의 vhost 파일이dispatcher/src/conf.d/available_vhosts
디렉터리의 파일에 대해 symlinks 이므로 없는 경우 symlink를 만드십시오. -
Cloud Manager - 웹 계층 구성 파이프라인 또는 RDE 명령을 사용하여 원하는 AEM as a Cloud Service 환경에 vhost 변경 사항을 배포합니다.
사용자 지정 Java™ 코드
이 옵션은 AEM Publish과 작성자 모두에 사용할 수 있습니다. 캐시 헤더를 업데이트하려면 사용자 지정 Java™ 코드의 SlingHttpServletResponse
개체(Sling 서블릿, Sling 서블릿 필터)를 사용합니다. 일반 구문은 다음과 같습니다.
response.setHeader("Cache-Control", "private");