Search code examples
apachecachingheaderaemcache-control

Apache dropping or removing or not storing a header in cache (Edge-Cache-Tag)


I have a weird situation where Apache 2.4 won't return a header from its cache. I have a AEM instance in Publisher mode returning these headers as part of its responses:

Date: Fri, 22 May 2020 22:26:21 GMT
X-Content-Type-Options: nosniff
Edge-Cache-Tag: /en-us/
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked

The flow works basically like this:

  • I hit Apache using a URL like https://ip:443/en-us/
  • Path gets rewritten to /content/some/other/path
  • Apache hits AEM on port 4503 to path /content/some/other/path
  • My web app returns a 200, including the headers I put above
  • Apache will see that its cache doesn't contain an entry for /content/some/other/path, and will create a cache entry for it.
  • Next and finally, Apache returns a 200.

When I hit again Apache to https://ip:443/en-us/, it responds with a 200, but it is not returning "Edge-Cache-Tag" header. I know the response comes from the cache, because first, I see an entry for "/content/some/other/path" in the cache, and if I hit Apache using https://ip:443/en-us/?foo=bar (a query param to bypass the cache), the header comes back, which means the response comes from the web app actually because the query param makes Apache bypass the cache.

I don't understand why Apache is removing "Edge-Cache-Tag" from its response. I have checked all my Apache config, and I don't have a single instructions to remove headers (like Header unset). Can't Apache cache "Edge-Cache-Tag"?


Solution

  • This is a normal behavior of the dispatcher. You have to configure Edge-Cache-Tag as one of the cached headers.

    https://docs.adobe.com/content/help/en/experience-manager-dispatcher/using/configuring/dispatcher-configuration.html

    The /headers property allows you to define the HTTP header types that are going to be cached by the Dispatcher. On the first request to an uncached resource, all headers matching one of the configured values (see the configuration sample below) are stored in a separate file, next to the cache file. On subsequent requests to the cached resource, the stored headers are added to the response.