跳转到内容
搜索文档

清除缓存键资源

最后更新 查看 MarkdownAgent 设置

通过 Cloudflare API 立即清除使用 Cache Keys 的资源。如果您使用 Cloudflare 的按 URL 清除,请包含自定义 Cache Key 中的标头和查询字符串。

目前,无法清除通过 Cache API 存储且使用 Worker 设置的自定义 cache key 的 URL。相反,请使用 Cache Rules 创建的自定义键。或者,使用清除所有内容、按标签清除、按主机清除或按前缀清除来清除资源。

要立即按 device_typegeolang 清除,请分别使用 CF-Device-TypeCF-IPCountryaccept-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
Purge Cached Contentbash
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
Purge Cached Contentbash
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
Purge Cached Contentbash
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"
						}
				}
		]
	}'

这篇文档对您有帮助吗?