You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cloudflare是否支持stale-while-revalidate?设置对应头未命中缓存咨询

Why You’re Not Seeing Cache Hits with stale-while-revalidate on Cloudflare

Hey there! Cloudflare definitely supports the stale-while-revalidate directive—let’s unpack why your current setup isn’t producing the cache hits you expect.

First, let’s break down your Cache-Control header:

public, max-age=0, stale-while-revalidate=30

The core issue here is likely the max-age=0 value. While stale-while-revalidate lets caches return stale content after the initial expiration window, max-age=0 tells Cloudflare the response is immediately expired the moment it’s cached.

In theory, this should still let Cloudflare serve the stale response for 30 seconds after the first request while revalidating in the background—but there are a few key catches:

  • Cloudflare’s edge logic might treat max-age=0 as a signal to avoid caching entirely in some scenarios, especially if other settings (like page rules or cache level configurations) override your header.
  • You might be misinterpreting "cache hits": when using stale-while-revalidate, the cache status will show as STALE (not HIT) when returning expired content. If you’re only looking for HIT in the CF-Cache-Status header, you’ll miss these valid stale responses.

Fixes to Try:

  1. Adjust max-age to a positive value
    If your use case allows, set max-age to a small non-zero number (e.g., public, max-age=10, stale-while-revalidate=30). This tells Cloudflare the response is fresh for 10 seconds, then can be served stale for another 30 while revalidating. You’ll see HIT statuses during the fresh window, and STALE statuses afterward.

  2. Verify your Cloudflare cache configuration
    Double-check if you have any page rules set to "Cache Level: Ignore Cache Control"—this would override your custom Cache-Control header. Make sure your cache level is set to "Standard" or "Cache Everything" (if appropriate) to respect your header directives.

  3. Inspect the CF-Cache-Status header
    Use browser dev tools or curl to check response headers. A STALE status means stale-while-revalidate is working as intended, even if it’s not the HIT you initially expected.

内容的提问来源于stack exchange,提问作者Dan Fabulich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:24:29