Stale-while-revalidate is not supported

Test case.

Response header:
Cache-Control: public, max-age=10, s-max-age=10, stale-while-revalidate=5

PHP code (forwarded “.js$” file to php script):
<? sleep(5); echo time(); exit; ?>

Result:
During cache expiration, duration of request takes additional 5 seconds, so Cloudflare NEVER provides stale content while revalidation.

Additional info:
Removing stale-while-revalidate from cache-control header hasnt any impact on flow what mean Cloudflare doesnt support this feature at all.

1 Like

Hi @mateusz.mania0,

Cloudflare may override your cache-control header when a Browser Cache TTL is set for any amount of time. To avoid this, you need to set it to Respect Existing Headers in the Dashboard > Cache app.

Also, if you use the Origin Cache-Control setting via page rule, this page explain some details about specific conditions that will make Cloudflare ignore "stale-while-revalidate’.

https://support.cloudflare.com/hc/en-us/articles/115003206852-Enabling-Origin-Cache-Control-with-Cloudflare-Page-Rules

Cloudflare attempts to revalidate the content with the origin before serving the response to the client.

I’m not sure but my question is, what is purpose to using stale-while-revalidate if user must wait for revalidated content? Revalidation will occurs in background as name of header (“stale-while-revalidate”) suggests?
It is proper implementation on CF side?

** Up **

Have you enabled origin cache control as shown in the screenshot in the article @floripare linked to? Also Edge Cache TTL needs to not be enabled.

Interaction with other Cloudflare features

Edge Cache TTL

Edge Cache TTL page rule settings override s-maxage and disable revalidation directives if present. The original Cache-Control header is passed downstream from our edge even if Edge Cache TTL overrides are present.

“Always online” disabled, origin cache control was enabled, edge cache ttl was disabled, proper headers was set on my server side.
I understand most of threads on Cloudflare community comes from people which has problems even with proper configuration but I dont have problems with configuration, I have problem with not working feature.

From https://tools.ietf.org/html/rfc7234#section-4.2.4:

A cache MUST NOT generate a stale response if it is prohibited by an
explicit in-protocol directive (e.g., by a “no-store” or “no-cache”
cache directive, a “must-revalidate” cache-response-directive, or an
applicable “s-maxage” or “proxy-revalidate” cache-response-directive;
see Section 5.2.2).

If you remove s-max-age from your header does the feature work as expected?

Response header:
Cache-Control: max-age=10, stale-while-revalidate=5

Result:
Stale content is not provided.
Requests in interval of about 1 second (triggered manually).

Page rules:

Cache settings:

What’s wrong with my configuration?

What’s wrong with my configuration?

+1 My company is looking to implement SWR. Please follow up if this issue is resolved.

1 Like

+1 My company is looking to implement SWR. Please follow up if this issue is resolved.

@mdee @floripare @cscharff
Looks like nobody’s interested in resolving this issue.
If there is no update during my product development, then I will leave from support cloudflare for users of my product.

3 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.