Cache network not working as expected

First of all, I want to apologize for my ignorance on the subject. I have read several contents from the Cloudflare guides but not much more, apologies.

I have a subdomain that has DNS configured as a proxy. The CNAME record resolves to a server with NGINX that returns images. The URL is of the type subdomain.something.com/path/image<CODE>.webp?w=500.

The server responds to the request with a cache-control header:
public, max-age=2592000 (30 days).

The first time I visit the image, as expected, it goes to the backend. The next visit is not always a HIT. I just noticed that the cf-ray is different and, therefore, the age header is also different, which makes me understand that different CDNs are making the request to my backend.

Here is an example of headers I receive from CF (part of the text is masked with * to avoid spam):

HTTP/3 200 
date: Thu, 30 May 2024 21:57:58 GMT
content-type: image/webp
cache-control: public, max-age=2592000
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade
x-back-id: ******
x-vhost: *****
last-modified: Thu, 30 May 2024 21:33:24 GMT
cf-cache-status: HIT
age: 276
report-to: {"endpoints":[{"url":"****"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
server: cloudflare
cf-ray: *****83148-MAD
alt-svc: h3=":443"; ma=86400

I thought that by just using the proxy, it would cache the content according to the headers and propagate it through the CF network (from my ignorance, that’s what I expected) but it is not the case.

I also tried creating a CACHE RULES (Website > Caching > Cache Rules) indicating the hostname ***, activating the “Cache eligibility” option to “Eligible for cache” and even forcing the TTL to 6 months in the “Edge TTL” option.

Another thing I tried is to enable Tiered Cache along with Cache Reserve but nothing. I think I’m just pressing buttons wildly without getting results.

Does anyone have any clues about what is happening or where I could start looking?

Thank you very much

Hi there,

Just to clarify this one point:

I just noticed that the cf-ray is different and, therefore, the age header is also different, which makes me understand that different CDNs are making the request to my backend.

The ray ID is always going to be different, even if an asset is a cache hit the ray ID will be unique.

I thought that by just using the proxy, it would cache the content according to the headers and propagate it through the CF network (from my ignorance, that’s what I expected) but it is not the case.

This is not the case, each pop, acts independently and would need to cache the assets - this means in theory you could have a request for each datacenter location on Cloudflare reaching your origin to cache that assets before its fully cached across all our regions. (unless you using tiered caching/cache reserve, which sounds like you are testing)

Another thing I tried is to enable Tiered Cache along with Cache Reserve but nothing. I think I’m just pressing buttons wildly without getting results.

This is a good idea in order to reduce the amount of requests to your origin and pull cached assets from other pops or from cache reserve.

Even if you have cache rules and set a high TTL - this does not mean that this will necessarily respected, read about retention here - Retention vs Freshness (TTL) · Cloudflare Cache (CDN) docs - but saying that cache reserve should be helping with this.

Saying all this - if you are making requests for the same resource repeatedly and sometimes seeing repeated misses, that does sound strange - but difficult to say what’s going on without doing some testing and being able to replicate - when are you doing these tests are all requests going to the same pop? You can tell by looking at the rayID with the suffix (-MAD) tells you your always hitting Madrid.

You could also try to make repeated requests to https:///cdn-cgi/trace if you look at the fl=684f32 line - if the number before the f is changing to a different number, it means your request is bouncing between different colos and this may be the reason you are seeing a cache miss.

Hope this helps!

Thank you Damian for your response. I appreciate it very much.

I understand what you are saying about the cf-ray and it makes sense.

About what you say about each pop being independent, it’s not really a CDN (if there are 100 actors and each one is going to make a request to the backend, there is no CND, no matter how much CF calls it that). A CDN is a network of interconnected servers that accelerates the load, and this is not the case. Well, it’s no longer a problem knowing this. I will start using AWS CDN service and stop paying for CF services.

Thank you very much for your prompt reply :smiley: