我试图让Apache缓存运行昂贵的PHP脚本的结果(它访问具有速率限制的第三方服务器),但是如果客户端发送一个If-Modified-Since
头,缓存就被绕过了。
CacheEnable disk /script.php
CacheLock on
CacheLockMaxAge 60
CacheIgnoreHeaders Set-Cookie
# prevent client explicitly requesting un-cached content
CacheIgnoreCacheControl on
CacheDetailHeader on
php脚本在其响应中设置以下标题:
Last-Modified
设置为当前时间,例如Sun, 20 Jun 2021 11:30:20 GMT
Expires
设置为当前时间加60秒,例如Sun, 20 Jun 2021 11:31:20 GMT
如果我发出以下请求:
GET /script.php HTTP/1.1
Host: example.com
Connection: close
然后缓存工作正常,而php脚本每分钟只运行一次,而来自缓存的其他请求也只能运行一次。
然而,发出以下请求:
GET /script.php HTTP/1.1
Host: example.com
Connection: close
If-Modified-Since: Sun, 20 Jun 2021 11:30:30 GMT
每次使用以下命令运行php脚本:
X-Cache-Detail: "cache miss: attempting entity save" from example.com
在回应中。
我在Ubuntu18.04上使用Apache2.4.29。
发布于 2021-06-25 09:29:37
的缓存手册
https://httpd.apache.org/docs/2.4/mod/mod_cache.html
CustomLog "cached-requests.log" common env=cache-hit
CustomLog "uncached-requests.log" common env=cache-miss
CustomLog "revalidated-requests.log" common env=cache-revalidate
CustomLog "invalidated-requests.log" common env=cache-invalidate
CacheDetailHeader打开
CacheIgnoreCacheControl On
CacheIgnoreQueryString on
使用url.com/my.php?jsessionid=123这样的会话令牌的
。
CacheIgnoreURLSessionIdentifiers jsessenionid
CacheLastModifiedFactor 0.99
CacheMinExpire 3600
之前删除if-Modfied报头。
Header unset Last-Modified
* Can also be used in htaccess
这是更多的调试在开始,因为它不适合在一个注释,但应该有助于Inc提高任何对象的缓存。
https://serverfault.com/questions/1067241
复制相似问题