Page rule not behaving as expected re: caching

Greetings community.

We are having a Page Rule for a specific endpoint which as a wildcard as the last URL parameter, which is a numerical identifier, ex:

ourapi.com/endpoint/{numerical_identifier}

Settings are as follow:

  • Browser Integrity Check: Off
  • Web Application Firewall: On
  • Security Level: Essentially Off
  • Cache Level: Cache Everything
  • Edge Cache TTL: 10 minutes

The expectation here is for CF to return the cached content (a simple JSON payload) for all requests, regardless of IP, location, headers, or any other criteria.

What we are observing is that it is cached for 10 minutes for each individual requester. In other words: we should see only one request per unique endpoint per 10 min on the Origin, which is not the case.

What are we missing?

Cloudflare has more than 300 locations worldwide, which means there are more than 300 different locations to fill the cache on.

Each individual location will require at least one request to your origin, in order to fill that cache.

  • Is your visitor reaching Amsterdam, Netherlands?
    That will be one request to your origin.

  • Is your visitor reaching Los Angeles, California, United States?
    That will be another request to your origin.

Your explanation makes it sound like you believe it should be: “Once it’s cached somewhere, it’s cached everywhere”, however, that is not the way CDN providers normally operate.

That said, -

A couple of CDN providers out there do actually have options, which you can enable, and which make it get closer to the “cached everywhere” approach than otherwise.

You can try enabling Tiered Cache:

https://dash.cloudflare.com/?to=/:account/:zone/caching/tiered-cache

3 Likes

Based on your response, you confirm there’s nothing wrong with our Page Rule settings?

Our tests were performed with people from the same region and on the same ISP. We have see the request for Person #1 reach the Origin and 5 minutes later, Person #2 performed the same request, which also reached the Origin, which is not expected.

Given the above, yes, this is what is expected.

Will definitely try, thanks for the link!

In addition to the excellent answer from @DarkDeviL , you should also consider that Cloudflare does not guarantee that a file is cached for the full TTL. More popular and smaller files stand better chances of staying in the cache for the whole TTL.

Especially when you request a file only once (and then wait a few minutes), it is almost guaranteed to be evicted from cache, as Cloudflare keeps files in memory cache for a short duration and only writes them to the SSD cache if they are requested for a second time while they are still in memory cache.

Here’s a bit more detailed information on Cloudflare’s cache-eviction policy:

2 Likes

@DarkDeviL @Laudian : thank you both for your guidance. After enabling Tiered Cache, we observed that traffic on our Origin for cached endpoints got reduced significantly.

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.