Hello there!
Sorry, I’m quite confused about this feature and after some testing, I’m more confused! 
I have a few endpoints that takes up to 4 sec to computate but the response (a json) isn’t updated very often, so I attempted to use Pages to cache it and it worked very well… Minus the fact that sometime, I still get the origin’s response time due the expired cache.
How this actually works? I thought that CF would refresh and cache the response every X (so if Edge TTL = 1 hour, at 1 hour and 1 sec, it will fetch origin and cache a new copy), thus I shouldn’t never get origin’s response.
My understanding is that maybe CF doesn’t do it automatically but only when someone hit the endpoints, then making the cache available for others for the given amount of time. Is this correct?
This is correct. Cloudflare will only fetch from your origin if there is not a copy in the cache.
Couple of things to keep in mind.
- Cache is per location, so if people are hitting your site from multiple locations, then multiple copies will be fetched from your origin.
- Cache is not guaranteed and can be evicted is other files need to be cached. IIRC, it is done based on last access time and plan level. As an example, if you are on a free plan and have a cached resource that has not been access for a day then it will be evicted over a resource on a higher plan level.
Thank you very much for your answer!
Could you please define “location” tho? It means region, IP, other? Is there any legit way to refresh and keep a copy of the cache on the edge, periodically?
Location is any of Cloudflare’s Datacenters. You could make a script that loads the assets through Cloudflare and which would cache them, but there is no native method through Cloudflare to periodically load assets into cache.