这些是创建 Cache Response Rule 时可以配置的设置。由于 Cache Response Rules 在 Cloudflare 收到源站响应后执行,请求和响应字段都可用于规则匹配。
| 字段 | 类型 | 说明 |
|---|---|---|
http.cookie |
String | 完整的 Cookie 标头值 |
http.host |
String | HTTP Host 标头 |
http.referer |
String | HTTP Referer 标头 |
http.user_agent |
String | HTTP User-Agent 标头 |
http.request.method |
String | HTTP 请求方法 |
http.request.uri |
String | 请求 URI |
http.request.uri.path |
String | URI 路径 |
http.request.uri.path.basename |
String | URI 路径的基名 |
http.request.uri.path.extension |
String | URI 路径中的文件扩展名 |
http.request.uri.query |
String | 查询字符串 |
http.request.uri.args |
Map | 以键值对形式表示的查询字符串参数 |
http.request.uri.args.names |
Array | 查询字符串参数名称 |
http.request.uri.args.values |
Array | 查询字符串参数值 |
http.request.full_uri |
String | 包含协议和主机的完整请求 URI |
http.request.headers |
Map | 以键值对形式表示的请求标头 |
http.request.headers.names |
Array | 请求标头名称 |
http.request.headers.values |
Array | 请求标头值 |
http.request.cookies |
Map | 以键值对形式解析的 Cookie |
http.request.accepted_languages |
Array | 解析后的 Accept-Language 标头值 |
| 字段 | 类型 | 说明 |
|---|---|---|
http.response.code |
Integer | 来自源站的 HTTP 响应状态码 |
http.response.headers |
Map | 以键值对形式表示的响应标头 |
http.response.headers.names |
Array | 响应标头名称 |
http.response.headers.values |
Array | 响应标头值 |
如果您选择 Edit expression 选项,可以输入上述任何响应字段。
此阶段提供以下函数:
- all
- any
- concat
- decode_base64
- ends_with
- len
- lookup_json_integer
- lookup_json_string
- lower
- regex_replace
- remove_bytes
- remove_query_args
- split
- starts_with
- substring
- to_string
- upper
- url_decode
- wildcard_replace
有关每个函数的说明,请参阅函数。
完整运算符列表,请参阅运算符。
Cache Response Rules 支持三种操作:
| 操作 | 说明 |
|---|---|
set_cache_settings |
在缓存前从源站响应中剥离标头(ETag、Set-Cookie、Last-Modified)。 |
set_cache_tags |
在响应上添加、移除或设置缓存标签,用于精准清除。 |
set_cache_control |
修改源站响应中的 Cache-Control 标头指令。 |
配置与源站响应缓存相关的设置。可用参数如下:
| 参数 | 类型 | 说明 |
|---|---|---|
strip_etags |
Boolean | 在缓存前从源站响应中剥离 ETag 标头。 |
strip_set_cookie |
Boolean | 在缓存前从源站响应中剥离 Set-Cookie 标头。 |
strip_last_modified |
Boolean | 在缓存前从源站响应中剥离 Last-Modified 标头。 |
API 信息
API 操作:set_cache_settings。
"action_parameters": {
"strip_etags": true,
"strip_set_cookie": true,
"strip_last_modified": true
}完整 API 示例请参阅通过 API 创建规则。
修改与响应关联的缓存标签。缓存标签可用于精准缓存清除。
| 参数 | 类型 | 说明 |
|---|---|---|
operation |
String | 必填。 取值之一:add、remove、set。 |
values |
Array | 缓存标签字符串列表,与 expression 互斥。 |
expression |
String | 计算结果为缓存标签数组的表达式,与 values 互斥。 |
API 信息
API 操作:set_cache_tags。
"action_parameters": {
"operation": "set",
"values": ["api-response", "dynamic-content"]
}"action_parameters": {
"operation": "add",
"expression": "split(http.response.headers[\"Surrogate-Keys\"][0], \",\", 1)"
}完整 API 示例请参阅通过 API 创建规则。
修改源站响应中的 Cache-Control 标头指令。
带时长值(秒)的指令:
max-ages-maxagestale-if-errorstale-while-revalidate
带可选限定符(标头名称)的指令:
privateno-cache
布尔指令:
no-storeno-transformmust-revalidateproxy-revalidatemust-understandpublicimmutable
可用参数取决于指令类型。
适用于 max-age、s-maxage、stale-if-error 和 stale-while-revalidate。
| 参数 | 类型 | 说明 |
|---|---|---|
operation |
String | 必填。 set 或 remove。 |
cloudflare_only |
Boolean | 启用后,此设置仅影响 Cloudflare 缓存内容的方式,访问者仍会收到原始指令。 |
value |
Integer | 以秒为单位的时长。当 operation 为 set 时必填。 |
适用于 private 和 no-cache。
| 参数 | 类型 | 说明 |
|---|---|---|
operation |
String | 必填。 set 或 remove。 |
cloudflare_only |
Boolean | 启用后,此设置仅影响 Cloudflare 缓存内容的方式,访问者仍会收到原始指令。 |
qualifiers |
Array | 用于限定指令的可选标头名称列表。 |
适用于 no-store、no-transform、must-revalidate、proxy-revalidate、must-understand、public 和 immutable。
| 参数 | 类型 | 说明 |
|---|---|---|
operation |
String | 必填。 set 或 remove。 |
cloudflare_only |
Boolean | 启用后,此设置仅影响 Cloudflare 缓存内容的方式,访问者仍会收到原始指令。 |
API 信息
API 操作:set_cache_control。
"action_parameters": {
"max-age": {
"operation": "set",
"value": 3600,
"cloudflare_only": true
},
"stale-if-error": {
"operation": "remove"
}
}完整 API 示例请参阅通过 API 创建规则。