Dispatcher vhost configuration

This option is the recommended approach for enabling caching however it is only available for AEM Publish. To update the cache headers, use the mod_headers module and <LocationMatch> directive in the Apache HTTP Server’s vhost file. The general syntax is as follows:

<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 Surrogate-Control
    Header unset Expires

    # 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.
    Header set 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.
    Header set 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.
    Header set Expires "Sun, 31 Dec 2023 23:59:59 GMT"
</LocationMatch>

The following summarizes the purpose of each header and applicable attributes for the header.

Web BrowserCDNDescription
Cache-ControlThis header controls the web browser and CDN cache life.
Surrogate-ControlThis header controls the CDN cache life.
ExpiresThis header controls the web browser and CDN cache life.
  • max-age: This attribute controls the TTL or “time to live” of the response content in seconds.
  • stale-while-revalidate: This attribute controls the stale state treatment of the response content at CDN layer when received request is within the specified period in seconds. The stale state is the time period after the TTL has expired and before the response is revalidated.
  • stale-if-error: This attribute controls the stale state treatment of the response content at CDN layer when the origin server is unavailable and received request is within the specified period in seconds.

Review the staleness and revalidation details for more information.