cachingcloudflarehttp-caching

Does Cloudflare support stale-while-revalidate?


Cloudflare documents a list of directives for the Cache-Control header, including stale-while-revalidate.

  • stale-while-revalidate=<seconds>
    When present in an HTTP response, the stale-while-revalidate Cache-Control extension indicates that caches MAY serve the response in which it appears after it becomes stale, up to the indicated number of seconds since the object was originally retrieved.

I set my Cache-Control header to public, max-age=0, stale-while-revalidate=30 but I never seem to get a cache hit. Does Cloudflare actually support this?


Solution

  • No, Cloudflare doesn't support stale-while-revalidate. The last word from them was in January 2022.

    https://community.cloudflare.com/t/when-will-cloudflare-fully-support-stale-while-revalidate-with-asynchronous-background-revalidation/287764/9?u=dfabulich

    To begin, we agree that this feature is good for the Internet and something that we will look to implement soon. The reason this isn’t currently supported is a technical limitation stemming from long-standing technical debt. The good news is that we’re currently in the process of getting rid of these limitations so that we can safely support more async features like this one. In the meantime, I thank you for your patience and look forward to supporting this soon.

    … nothing has changed since then.

    Cloudflare does have a feature that looks kinda like SWR if you squint and turn your head a little, a feature where parallel requests can receive stale UPDATING content during a slow revalidation. But that feature (which is genuinely interesting) is on by default, and isn’t affected by the SWR header. (Even setting stale-while-revalidate=0 doesn’t turn the feature off!)

    I wrote up a lengthy analysis of Cloudflare's nonexistent SWR support in 2018, but it did me no good; Cloudflare has never directly replied to it. https://community.cloudflare.com/t/does-stale-while-revalidate-work/24161/6?u=dfabulich