通过 Cloudflare API 立即清除使用 Cache Keys 的资源。如果您使用 Cloudflare 的按 URL 清除,请包含自定义 Cache Key 中的标头和查询字符串。
目前,无法清除通过 Cache API 存储且使用 Worker 设置的自定义 cache key 的 URL。相反,请使用 Cache Rules 创建的自定义键。或者,使用清除所有内容、按标签清除、按主机清除或按前缀清除来清除资源。
要立即按 device_type、geo 或 lang 清除,请分别使用 CF-Device-Type、CF-IPCountry 或 accept-language。按标签/主机名清除和清除所有内容不受自定义 Cache Keys 使用的影响。
对于基于设备类型的 Cache Key,通过在 API 清除请求中传递 CF-Device-Type 标头来清除资源(有效标头包括 mobile、desktop 和 tablet)。
请参阅下面的示例 API 请求,立即清除根网页上的所有移动资源。
Required API token permissions
At least one of the following token permissions is required:Cache Purge
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"files": [
{
"url": "http://my.website.com/",
"headers": {
"CF-Device-Type": "mobile"
}
}
]
}'通过指定两字母国家代码,立即清除基于位置的 Cache Key 的资源。下面使用西班牙作为示例。
Required API token permissions
At least one of the following token permissions is required:Cache Purge
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"files": [
{
"url": "http://my.website.com/",
"headers": {
"CF-IPCountry": "ES"
}
}
]
}'对于基于语言的 Cache Key,通过传递 accept-language 标头来清除资源。请参阅下面的示例 API 请求,立即清除所有简体中文 (PRC) 资源。
Required API token permissions
At least one of the following token permissions is required:Cache Purge
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"files": [
{
"url": "http://my.website.com/",
"headers": {
"accept-language": "zh-CN"
}
}
]
}'