Hi there,
Have been checking this desired feature, which is announced by Cloudflare and detailed in developer documentation at:
https://developers.cloudflare.com/cache/concepts/cache-control/
In my case, already checked “Always online” is disabled and I am not using API methods cache.match or cache.put, since not using workers at all.
I did just test using this method:
- a simple php file which does echo a simple number o string, or a current date.
- origin nginx adding this header for every request:
add_header Cache-Control “public, stale-if-error=180, stale-while-revalidate=180, max-age=3”;
then:
- php does echo 1
- curl with -v to see the response headers from Cloudflare
- Cloudflare created cache: response body is “1”… ok
- curl again within 3 seconds
- Cloudflare response with a HIT
- modify php to echo 2
- wait more than 3 seconds but less than 180 and now the cache entry is expired and staled
- curl again: Cloudflare response with an EXPIRED but the body output is “2” instead of staled “1”
- tested multiple times with same result
ok, IT’S NOT WORKING, Cloudflare is not serving staled content while revalidating expired cached request, since it is serving the updated php output…
It is even more obvious if you add a sleep line to php script to delay output let’s say by 10 seconds, you will notice you will need to wait those 10 seconds while requesting the expired cached request.
ok, let’s try using the cache rules… there is a new setting for your rules for stale-while-revalidating. It is written in this form:
"### Serve stale content while revalidating (Optional)
Define if Cloudflare should serve stale content while revalidating it with the origin.
Serve stale content while revalidating
When off, Cloudflare waits for the origin before responding."
So I guess I need to enable it and just do it…
- enabled this optional “Serve stale content while revalidating”
- wait one or two minutes
- test again
- test again
- test again
- exactly same result… IT DOES NOT WORK
Even more and more strange, If I have a look at cache rules via API, I notice this configured setting is written in the form:
"serve_stale": {
"disable_stale_while_updating": true
},
WHAT!?!?!?!? So the name of the variable is just the opposite of what Cloudflare WEB UI tell me to do!!! Ok, what a mess, will now disable it via WEB UI and put setting to “off”. Now it is:
"serve_stale": {
"disable_stale_while_updating": false
},
I don’t know if trust of what WEB UI is telling me, or to trust the name of the setting variable when calling API. But will try once again.
- wait one or two minutes
- test again
- test again
- test again
- exactly same result… IT DOES NOT WORK
So it just simply do not work, and did ensure:
- not using “Always online”
- not using API cache methods
- cache control header is always “public, stale-if-error=180, stale-while-revalidate=180, max-age=3”
- tried with NO cache setting for “Serve stale content while revalidating”
- tried with cache setting Serve stale content while revalidating: ON
- tried with cache setting Serve stale content while revalidating: OFF
Feaure does not work at all.
Ok, it does not work but:
- there is an option for in the cache rules
- there is an setting for it in the API/cache rules
- and more important, IT IS specified in the Cloudflare documentation
So at last, my desired feature, announced by Cloudflare as valid, is not working and I have just wasted my time testing and testing.
And checked community forums… there are some entries written months ago, it works, it does not work… nobody knows. But the fact it is, as said, specified at documentation and there are options for it in the API/UI… I guess IT IS SUPPOSED TO WORK.
So I just notice…
People, if you are answering here just to say “it works!”, please do tell what about your current configuration for cache rules and more important, the method you followed to test and ensure it does work.
Regards,
Gino