返回访问者 IP 与时间戳的 JSON 端点,6 种 Cache-Control 策略用于对比边缘缓存行为。
| 路径 | Cache-Control | 预期 cf-cache-status |
|---|---|---|
| /api/no-store | no-store | DYNAMIC |
| /api/no-cache | no-cache, max-age=0 | REVALIDATED |
| /api/short | public, max-age=10 | 10s 内 HIT |
| /api/long | public, max-age=3600 | 1h 内 HIT |
| /api/private | private, max-age=0 | DYNAMIC(边缘不缓存) |
| /api/error | 404 + public, max-age=60 | 观察 4xx 是否被缓存 |
# 第一次请求(应 MISS)
curl -sI https://your.domain/api/short
# 10 秒内再请求(应 HIT,age 递增)
curl -sI https://your.domain/api/short
# 重点关注响应头:
# cf-cache-status: HIT | MISS | EXPIRED | REVALIDATED | DYNAMIC | BYPASS
# age: <秒> (HIT 时出现)
# cache-control: <策略>
# cf-ray: <边缘数据中心 ID>
{
"ip": "203.0.113.42",
"timestamp": "2026-09-07T12:34:56.789Z",
"path": "/api/short",
"cache_control": "public, max-age=10",
"cf_ray": "8a1b2c3d4e5f6789-SJC",
"cf_country": "CN"
}