跳转到内容
搜索文档

自定义缓存

最后更新 查看 MarkdownAgent 设置

Cloudflare Cache Rules 与源站 Web 服务器设置的一些可能组合包括:

在源站 Web 服务器上为静态内容创建目录

例如,在源站 Web 服务器上创建 /static/ 子目录,并创建匹配以下表达式的 Cache Everything Cache Rule:

  • 使用 Expression Builder:Hostname contains "example.com" AND URI Path starts with "/static"
  • 使用 Expression Editor:(http.host contains "example.com" and starts_with(http.request.uri.path, "/static"))

为静态页面附加唯一文件扩展名

例如,在源站 Web 服务器上为资源创建 .shtml 文件扩展名,并创建匹配以下表达式的 Cache Everything Cache Rule:

  • 使用 Expression Builder:Hostname contains "example.com" AND URI Path ends with ".shtml"
  • 使用 Expression Editor:(http.host contains "example.com" and ends_with(http.request.uri.path, ".shtml"))

向资源 URL 添加查询字符串以标记内容为静态

例如,在源站 Web 服务器上为资源添加 static=true 查询字符串,并创建匹配以下表达式的 Cache Everything Cache Rule:

  • 使用 Expression Builder:Hostname contains "example.com" AND URI Query String contains "static=true"
  • 使用 Expression Editor:(http.host contains "example.com" and http.request.uri.query contains "static=true")

匹配 Cache Everything Cache Rule 的资源,如果源站 Web 服务器发送 max-age=0privateno-cache 的 Cache-Control 标头,或 Expires 标头已过期,仍然不会被缓存。在 Cache Everything Cache Rule 中包含 Edge Cache TTL 设置,以额外覆盖源站 Web 服务器的 Cache-Control 标头。

这篇文档对您有帮助吗?