http response shows Expires in 1981 when using mod_cache

Daniel asked:

I’m setting up Apache caching on CentOS using mod_cache and mod_cache_disk with the configuration at the bottom of this post but the page is not cached. I included CacheDetailHeader on to get some debug info.

When I hit the page, the HTTP response shows X-Cache-Detail: "Expires header already expired; not cacheable" and the Expires header is set to some date in 1981, despite the date being correct.

Date: Mon, 19 Aug 2019 23:39:03 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT

The full configuration. CacheRoot exists and is writable for the Apache user.

# The following line could be required or not depending on your Apache installation
LoadModule cache_module modules/mod_cache.so

<IfModule mod_cache.c>
    CacheQuickHandler off
    CacheDetailHeader on 

    CacheIgnoreNoLastMod On
    CacheDefaultExpire 7200

    CacheIgnoreCacheControl On
    CacheLastModifiedFactor 0.5
    CacheIgnoreHeaders Set-Cookie Cookie
    CacheHeader on
    CacheLock on
    CacheDisable /wp-admin
    CacheDisable /wp-login.php
    CacheDisable /wp-cron.php

    SetOutputFilter CACHE
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/rss+xml text/xml image/svg+xml

    # The following line could be required or not depending on your Apache installation
    LoadModule cache_disk_module modules/mod_cache_disk.so

    <IfModule mod_cache_disk.c>
        CacheRoot /var/cache/apache2/mod_cache_disk
        CacheEnable disk /
        CacheDirLevels 2
        CacheDirLength 1
        CacheMaxFileSize 2000000
    </IfModule>
</IfModule>

My answer:


PHP is configured to send cache disabling headers, including the Expires: header you show, on pages which start a session. This date corresponds to the birthday of the PHP developer who implemented this feature.

You can configure this behavior by setting session.cache_limiter in php.ini.

If you are running WordPress there should not be a need to change this from its default of nocache, as pages with this header correspond to pages being sent to users logging in or already logged in and thus shouldn’t be cached by Apache anyway. You might change it to private or private_no_expire to allow logged in users’ browsers to cache the pages, though.

To test your cache, use an incognito window and hit your WordPress site while logged out.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.