Browser TTL 控制图像在浏览器缓存中保留的时间,并专门配置 cache-control 响应标头。
默认情况下,图像的 TTL 设置为两天,以满足用户需求,例如在同一 Custom ID 下重新上传图像。
您可以使用两个自定义设置来控制 Browser TTL:账户或命名变体。要调整浏览器应保留图像在缓存中的时间,以秒为单位设置 TTL,类似于设置 max-age 标头。值应为 1 小时到 1 年之间的间隔。
按账户设置 Browser TTL 会覆盖默认 TTL。
curl --request PATCH 'https://api.cloudflare.com/client/v4/accounts/{account_id}/images/v1/config' \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"browser_ttl": 31536000
}'当所有图像的 Browser TTL 设置为一年时,cache-control 标头的响应本质上是 public、max-age=31536000、stale-while-revalidate=7200。
为命名变体设置 Browser TTL 是更细粒度的选项,在创建或更新图像变体时覆盖上述所有设置,特别是 browser_ttl 选项(以秒为单位)。
curl 'https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_TAG>/images/v1/variants' \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"id":"avatar",
"options": {
"width":100,
"browser_ttl": 86400
}
}'当使用此变体请求的图像的 Browser TTL 设置为一天时,cache-control 标头的响应本质上是 public、max-age=86400、stale-while-revalidate=7200。