[ PROMPT_NODE_24028 ]
Cache Reserve 配置说明
[ SKILL_DOCUMENTATION ]
# Cache Reserve 配置
## 仪表板设置
**启用步骤:**
bash
# 导航至仪表板
https://dash.cloudflare.com/caching/cache-reserve
# 点击 "Enable Storage Sync" 或 "Purchase" 按钮
**先决条件:**
- 需要付费的 Cache Reserve 套餐或 Smart Shield 高级版
- Cache Reserve 若要发挥最佳性能,**必须**开启分层缓存 (Tiered Cache)
## API 配置
### REST API
bash
# 启用
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/cache/cache_reserve"
-H "Authorization: Bearer $API_TOKEN" -H "Content-Type: application/json"
-d '{"value": "on"}'
# 检查状态
curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/cache/cache_reserve"
-H "Authorization: Bearer $API_TOKEN"
### TypeScript SDK
bash
npm install cloudflare
typescript
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env.CLOUDFLARE_API_TOKEN,
});
// 启用 Cache Reserve
await client.cache.cacheReserve.edit({
zone_id: 'abc123',
value: 'on',
});
// 获取 Cache Reserve 状态
const status = await client.cache.cacheReserve.get({
zone_id: 'abc123',
});
console.log(status.value); // 'on' 或 'off'
### Python SDK
bash
pip install cloudflare
python
from cloudflare import Cloudflare
client = Cloudflare(api_token=os.environ.get("CLOUDFLARE_API_TOKEN"))
# 启用 Cache Reserve
client.cache.cache_reserve.edit(
zone_id="abc123",
value="on"
)
# 获取 Cache Reserve 状态
status = client.cache.cache_reserve.get(zone_id="abc123")
print(status.value) # 'on' 或 'off'
### Terraform
hcl
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
}
provider "cloudflare" {
api_token = var.cloudflare_api_token
}
resource "cloudflare_zone_cache_reserve" "example" {
zone_id = var.zone_id
enabled = true
}
# Cache Reserve 需要分层缓存
resource "cloudflare_tiered_cache" "example" {
zone_id = var.zone_id
cache_type = "smart"
}
### Pulumi
typescript
import * as cloudflare from "@pulumi/cloudflare";
// 启用 Cache Reserve
const cacheReserve = new cloudflare.ZoneCacheReserve("example", {
zoneId: zoneId,
enabled: true,
});
// 启用分层缓存 (必需)
const tieredCache = new cloudflare.TieredCache("example", {
zoneId: zoneId,
cacheType: "smart",
});
### 所需 API 令牌权限
- `Zone Settings Read`
- `Zone Settings Write`