The docs under the revalidation section describes quite a few possible cases where stale-if-error does not apply:
The stale-if-error directive is ignored if Always Online is enabled or if an explicit in-protocol directive is passed. Examples of explicit in-protocol directives include 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.
Does any of these cases apply to the URL you are referring to?
Itās not a specific URL in a sense, it is more of an actual Error 508 from origin happening, and stale-if-error did not serve a stale cached page.
I tested with PHP by simulating an internal page to output 508, I did not get the cached page served. The page was cf-cache-status: HIT before origin cache-control times out, i.e. max-age=60
In this case, we should consider the cached asset for https://www.sgtrains.com/test-cf?http=508 the 508 response, which would be served expired, since the origin is reachable and the 508 response exists in the cache. (Another note, is that the behavior for 508 responses isnāt customized as for 500-504, this 508 was cached due to the cache everything page rule)
If the cached asset was a 200 response, and then the server returned a 508 error, then we should be serving a stale response.
I cannot test this as with the cache everything enabled, since each URL is considered separately for caching, so ?http=508 is a different cached asset, than ?http=508 or ?http=200.
Could you open a ticket and reply to this thread with the ticket number? [email protected]
Regarding origin cache control, due to the CDN-Cache-control directives, cache-control shouldnāt be considered by the Cloudflare cache.
Return the CDN-Cache-Control response header which Cloudflare evaluates to make caching decisions. Cache-Control , if also returned by the origin, is proxied as is and does not affect caching decisions made by Cloudflare. Additionally, CDN-Cache-Control is proxied downstream in case there are other CDNs between Cloudflare and the browser.
However, the cache-control could influence the cache-control response from Cloudflare to the client.
If the cached asset was the 508 Response itself, then Cloudflare will revalidated the 508. So the tests weāve done to this point against https://www.sgtrains.com/test-cf?http=508, are expectedly returning that 508 response.
Now, the behavior that the user asking about is what asset would be delivered for functioning page (no error response), that then returns a 508 error.
In this case, I would agree the expected behavior would be a stale asset, but youād first need to confirm that the asset is in the cache by first seeing a cf-cache-status HIT on a different non-error status. This canāt be achieved with the URL above, or similar tests, due to Cache Everything caching query strings separately.
The pageās code has been updated to simulate Error 508 whenever the current time minute is even number, to eliminate the usage of the query string as suggested.
Otherwise it should output an āOKā with 200.
Have also cleared the cache of the page just in case.