Hey, I have a website with not that many visitors, however, it will have fairly frequent posts (a news site)
So I would like to set edge cache to 1 hour, since i have a pro plan (so you can see the news articles on my homepage)
But it would also be cool to cache everything so it would be faster on regions not close to my server
After that 1 hour, would Cloudflare automatically send a request to my origin server and update the cached content, or would it wait for the first visitor to come in after 1 hour and send the cache request then?
I am asking this because i probably wont have a visitor every hour from each location, and it would be nice to serve them the fresh newly cached content
I understand that i have to have a visitor from each location first to be cached, i am asking about the 1 hour intervals after it, like for example if ill get a visitor 12 hours later from that location, will he get the news site how it was like 1 hour, or 12 hours before his visit.
My server can handle it, its a vps with 4 dedicated cores and 16 gb memory.
Also, is my setup correct if i want to achieve what i just said, and is it possible?
Should i add more settings? Do i need Origin Cache Control?
CF would wait for the first visitor, subsequent visitors will get the cached versions within the 1 hour limit.
Cloudflare will not fetch anything on your site (except for the few “Always Online” pages) without it being requested first by a visitor. At this point, this first visitor gets the page and files, and they are cached for subsequent visitors. That happens at each of the datacenters, so a visit to CDG will only create cache at CDG.
You could set either GTMetrix or webpagetest.org to visit your site hourly from a few datacenters, check their documentation.
The Always Online feature won’t help you. It will crawl your website every 3 days, since you are on a Pro plan, but every time you purge everything, these pages are also purged. For details, please see item 11 here:
Also, keep in mind that the Browser Cache TTL and Edge Cache TTL override the cache control values from your origin, but only as long as they set a higher TTL. So you need to make sure your origin is not sending headers instructing either the browser or proxies to cache the HTML pages for longer than 1 hour.
Also you mentioned that the visitors will get the cache done with the 1 hour limit, to make it easier for me to understand could i ask with an example?
The first visitor will come from new york at 1pm, ill create a new post at 4pm, then the next visitor from new york arrives at lets say 6pm, will the second visitor see my new post created at 4pm, with fast loading, from the Cloudflare servers, or will he have to request my origin server since the cache has expired
(what im trying to ask is does Cloudflare refresh their cache hourly or not, because if it just simply expires after an hour and my users have to connect to my origin server all the time then that means that its not worth it to use cache everything with low edge ttl and low visitors/region)
sorry for needing an example, its not my native language plus im not a programmer (i think thats obvious lol), so its easier for me to understand this way.
In your scenario, the second visitor will most likely see a fresh page retrieved from your origin. There’s no point in showing the 1pm cached page, even if it was still available, when the content has already changed at 4pm.
What you can do is set a higher Edge Cache TTL, and purge the cache upon publication of new stories. This actually can be done automatically if you use the Cloudflare plugin, and set the Automatic Cache Management feature within it. So if the day is a slower day, in terms of updates, the second visitor has a higher chance of getting a faster, cached page, but will be served a fresh page should the content change in between visits.
Actually I’m not sure what to suggest here as far as page rules vs the workers solutions. Thought I pointed to that solution, I’m not so familiar with its workings, as I haven’t yet used it in any of my sites. Perhaps @sdayman may help you with these questions, as he’s a lot more familiar with it than I am.
As far as I know the Cloudflare Plugin is not needed for that solution to work, only its own plugin.