About the Pages cache

We use Pages and Functions. How can we provide up-to-date information without it being cached by CDNs or browsers?

We do not want to cache html because we are dealing with information that is updated from time to time, such as weather forecasts. But our information is cached, so the weather forecast from a few days ago is still displayed.

We have isolated the cause. Functions are correctly updated. We can access the Function API with a browser or curl to get the latest information.

We tried to retrieve it with cache disabled as follows.
curl -H ‘Cache-Control: no-cache, no-store’ -v ‘https://XXX.XXX/XXX/XXX

However, the header returned only old information, including maxage, etc., as follows
However, only old information was returned, including max-age=604800 in the header.

We have tried Purge Cache’s Purge Everything. But the information is still out of date. We have also cleared the browser cache. But the information is still out of date. How can we always get new information?

Pages should handle it’s own caching & flushes - do you have any custom Page Rules setup for caching?

@KianNH Thanks for your reply.
Where and how is it set up?

We did ‘Purge Cache - Purge Everything’ and it did not seem to work. We changed the Browser Cache TTL to 2minutes, but it seemed to have no effect. Where and how should we set up other than this?

Resources such as images may be cached, but the values returned by Functions and the HTML generated by reading them must not be cached.

Tried using CDN-Cache-Control or Cloudflare-CDN-Cache-Control https://developers.cloudflare.com/cache/about/cdn-cache-control/

Blog https://blog.cloudflare.com/cdn-cache-control/

@eva2000, Thank you for your message!
We don’t know much about CDN-Cache-Control or Cloudflare-CDN-Cache-Control yet, so we learn about them.

We have created the following rules in Page Rules.

[Domain Name]/*
Cache Level: Bypass

We have also cleared all browser caches. But our data is still cached. What are we doing wrong?

It is stated that if no-store is set in the Cache-Control header, it will not be cached.
https://developers.cloudflare.com/cache/about/default-cache-behavior/

We have set it in the following way and they are still cached.

nuxt.config.js

  serverMiddleware: ["~/middleware/response-header.js"],

middleware/response-header.js

export default (req, res, next) => {
  res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
  next();
};

Can someone give us an example of a setting that is not cached and where to set it, rather than a URL that describes the setting?

We read here too, but did not see here how not to cache.
https://developers.cloudflare.com/cache/about/cdn-cache-control/

Cloudflare Pages is already ‘cached’ on the edge so it doesn’t need (or use) the typical cache that you’re referring to - if you hit one of the pages you’re having an issue with using curl -sSI https://domain.com, what’s the CF-Cache-Status header that you get back?

The behaviour of Pages specifically is described here: https://developers.cloudflare.com/pages/platform/serving-pages/#caching-and-performance

It’s advised that you don’t add any Page Rules or changing the caching behaviour yourself.

We sincerely thank you for wasting your valuable time on our behalf.
It appears that CF-Cache-Status is currently set to DYNAMIC. Other information is as follows

HTTP/2 200 
date: Wed, 04 May 2022 23:38:23 GMT
content-type: text/html; charset=utf-8
access-control-allow-origin: *
cache-control: public, max-age=0, must-revalidate
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
report-to: {"endpoints":[{"url":"~~~omitting~~~"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
cf-cache-status: DYNAMIC
server: cloudflare
cf-ray: ~~~omitting~~~
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

When we tried a slightly different URL the cache-control was different.
However, CF-Cache-Status was also DYNAMIC here.

HTTP/2 200 
date: Wed, 04 May 2022 23:44:42 GMT
content-type: text/html; charset=utf-8
access-control-allow-origin: *
age: 345282
cache-control: public, s-maxage=604800
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
x-robots-tag: noindex
report-to: {"endpoints":[{"url":"~~~omitting~~~"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
server: cloudflare
cf-ray: ~~~omitting~~~
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

I’d recommend removing any Page Rules or headers that you’re setting specify & making a new deployment - as far as I’m aware, the default caching policy on Pages will automatically handle purges and determining if a 200 OK or 304 Not Modified response is returned on it’s own.

When there’s no Page Rules or any other headers that you’ve added with the intent of changing the caching behaviour, new deployments should remove old versions of the assets on their own (with the Purge Everything button being a fallback to that).

Documentation like https://developers.cloudflare.com/cache/about/cdn-cache-control/ makes sense for the ‘normal’ Cloudflare caching but Pages aren’t quite the same as they operate, functionally, using the underlying cache technology anyways - regardless of the DYNAMIC returned in the CF-Cache-Status header.

We had already removed the Rule, but took your advice and set the Browser Cache TTL back to the default value of 4 hours. In addition, we implemented Purge Everything in the Purge Cache.
To us there appears to be no change in that.

HTTP/2 200 
date: Thu, 05 May 2022 00:00:41 GMT
content-type: text/html; charset=utf-8
access-control-allow-origin: *
age: 257430
cache-control: public, s-maxage=604800
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
x-robots-tag: noindex
report-to: {"endpoints":[{"url":"~~~omitting~~~"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
server: cloudflare
cf-ray: ~~~omitting~~~
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
HTTP/2 200 
date: Thu, 05 May 2022 00:01:39 GMT
content-type: text/html; charset=utf-8
access-control-allow-origin: *
age: 346299
cache-control: public, s-maxage=604800
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
x-robots-tag: noindex
report-to: {"endpoints":[{"url":"~~~omitting~~~"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
server: cloudflare
cf-ray: ~~~omitting~~~
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

Cloudflare is not caching the resource. The cache control s-max-age is being set elsewhere and is a caching server directive not a client one. Perhaps there is an intermediate cache layer?

@cscharff Thank you for your reply.
Isn’t it Cloudflare that is caching them?
How can we clear it up?

Talk to whoever mange’s the intermediary systems and the origin. Cloudflare is pulling ‘Dynamic’ content from whatever is specified as the origin according to the cf-cache-status header. If it is stale it is downstream and outside of Cloudflare’s control.

We believe we are using Cloudflare directly. Is there an intermediary service out there that we don’t know about? We don’t know who it is.

We are confused because we have gotten multiple advices.
If we don’t have any Rule settings or cache settings, are they not cached?

We have 3 projects running on Cloudflare Pages and one of them appears to be not cached with no settings. However, the other two projects appear to be cached with the same settings. We do not know the difference.

Our weather site still shows the May 1 forecast. There is absolutely no value in that. We want to clear our cache as soon as possible.

OK. just finding out that Cloudflare is not caching is a big step forward for us. We will continue to look into the remaining issues. Thank you.