CDN and Cache-Control headers


#1

Hi, let me just say that I’m new to the whole cloudflare thing, so apologies if this is not a question I should be asking in here.

I’ve been playing with Cache-Control headers for an API that returns JSON. I have managed to set up a PageRule and requesting the same resource multiple times seems to only go to cloudflare and return with the same data :smile:
and after 4 mins when a new call is made, it goes to my API and that value is cached.

So everything seems fine and perfect, but here is my issue (it may not be an issue, it might be just how it works):

  1. I make a call to the URL on my desktop (I get a response and subsequent calls get the same response)
  2. I use the same URL on my mobile (connected via 4G), but I don’t get the same response as from step 1. (however this call seems to cache the data it received and I’ll get the same response for the next 4 mins).

I was expecting the cached data received by my desktop to be the same thing I’d get on my mobile, is this not how it works?

I hope this makes some sort of sense.

Thanks


#2

If you’re not getting the exact same data from both calls the most likely cause is the calls are somehow different.

It’s also possible that your phone and desktop are connecting to different POPs as we maintain our cache on a per POP basis. If you turn off cellular and use just wifi you can force your phone over the same connection as your desktop which should eliminate the different POP option.

In your logs do the calls appear identical?


#3

Hi,

not sure what a POP is but if I use my WiFi network for my phone and PC I get the same response. On my desktop I can see the headers say cf-cache-status:HIT after first using the API on my phone. As soon as I go back to 4G connection I get a different response.

So guess I am getting a different POP rather than the requests being slightly different.

So I take it, this is the way it is meant to work, so I think all is fine. Might have to see if there is some other technique to be able to cache data from my API or put in a layer in between Cloudflare and the API for caching.


#4

POP is short for Point Of Presence. It’s referencing our data center locations around the world.


#5

As @ryan said a POP is one of our points of presence (120 word wide). A device will connect tot he closest POP based on BGP routing and that can be a different pop depending on the network (a user in London will get a different POP (usually) than a user in Berlin. Mobile networks can be much more consolidated than a physical network so sometimes you’ll see much different localtions being the closest for a mobile network than a physical one.


#6

ah ok, I had just found it in the Glossary: https://www.cloudflare.com/learning/cdn/glossary/data-center/ (in case someone else wants to know more) :smile:

Thanks for the info guys, think I’ll start using cloudflare and see how well the API does with it.