I'm trying to get Apache to cache the results from running an expensive PHP script (it accesses a third party server which has rate limiting) but it seems if the client sends an If-Modified-Since
header the cache is bypassed.
CacheEnable disk /script.php
CacheLock on
CacheLockMaxAge 60
CacheIgnoreHeaders Set-Cookie
# prevent client explicitly requesting un-cached content
CacheIgnoreCacheControl on
CacheDetailHeader on
The php script sets the following headers in its response:
Last-Modified
set to the current time, e.g. Sun, 20 Jun 2021 11:30:20 GMT
Expires
set to the current time plus 60 seconds, e.g. Sun, 20 Jun 2021 11:31:20 GMT
If I issue the following request:
GET /script.php HTTP/1.1
Host: example.com
Connection: close
Then the caching works correctly and the php script is only run once a minute with other requests being served from the cache.
However issuing the following request:
GET /script.php HTTP/1.1
Host: example.com
Connection: close
If-Modified-Since: Sun, 20 Jun 2021 11:30:30 GMT
Runs the php script every time with:
X-Cache-Detail: "cache miss: attempting entity save" from example.com
in the response.
I'm using Apache 2.4.29 on Ubuntu 18.04.