【问题标题】:Cloudflare not caching files even when headers are "Cache-Control: public, max-age=86400"即使标题为“Cache-Control:public,max-age=86400”,Cloudflare 也不会缓存文件
【发布时间】:2018-11-12 05:17:49
【问题描述】:

当我使用 curl 命令时,所有标题都是正确的,但文件没有缓存为

CF-缓存状态:MISS

由 curl 命令显示。

> < HTTP/1.1 200 OK < Date: Sat, 02 Jun 2018 05:57:28 GMT <
> Content-Type: image/png < Content-Length: 2293 < Connection:
> keep-alive < Set-Cookie:
> __cfduid=d3cf179afd212660124585350d19e88c81527919048; expires=Sun, 02-Jun-19 05:57:28 GMT; path=/; domain=.mayan.cf; HttpOnly <
> X-Powered-By: Express < Accept-Ranges: bytes < Cache-Control: public,
> max-age=86400 < Last-Modified: Fri, 01 Jun 2018 15:39:06 GMT < ETag:
> W/"8f5-163bc009a0c" < CF-Cache-Status: MISS < Expires: Sun, 03 Jun
> 2018 05:57:28 GMT < Server: cloudflare < CF-RAY: 4247aec4300930f6-SIN
> <  { [1905 bytes data]
> * Connection #0 to host mayan.cf left intact

【问题讨论】:

    标签: node.js nginx caching cloudflare


    【解决方案1】:

    Cloudflare 使用一些启发式方法尝试仅根据请求来猜测内容是静态的(可缓存的)还是动态的。如果它在请求时猜错了,它不会缓存响应。您可以通过将页面规则“缓存级别”设置为“缓存所有内容”来禁用此启发式方法——然后 Cloudflare 将假定响应始终是可缓存的。

    尝试设置该页面规则,看看是否有帮助。

    【讨论】:

    • 感谢这个页面规则真的很有帮助。
    【解决方案2】:

    如果 Cache-Control 标头设置为“private”、“no-store”、 “no-cache”或“max-age=0”,或者如果响应中有一个 cookie, 那么 Cloudflare 将不缓存资源。

    https://support.cloudflare.com/hc/en-us/articles/202775670-How-Do-I-Tell-Cloudflare-What-to-Cache-

    【讨论】:

    • 我已经读过了,看看输出:-Cache-Control: public, > max-age=86400 in question。
    • @gautamkumar 查看输出Set-Cookie: __cfduid=...
    • @AlexeyTen 该 cookie 是由 Cloudflare 自己添加的。这不算数。
    猜你喜欢
    • 2021-05-18
    • 2023-01-28
    • 2015-10-19
    • 2019-07-09
    • 2017-03-21
    • 2018-03-14
    • 1970-01-01
    • 2019-07-04
    • 2018-11-24
    相关资源
    最近更新 更多