Maximizing Edge Cache

I have a site with user-generated content that might not change for an hour or two. These are unique pages - ie, example.com/article/123

My goal is to send from my origin server some sort of “signal” to CF to keep this content on the edge - thus giving the hamsters in the wheel time to catch up with other stuff.

I thought this was with the Cache-Control: public,s-maxage=3600 type header. When I do that, CF still has cache status as dynamic. I tried creating a page rule (with an exact URL to test), and it didn’t do much help.

Can anyone give me a push in the right direction? My guess is I need a combination of page rule / header to let CF know which content I want out on the edge, but I can’t seem to get a working combo going.

Can I create a page rule based off http status code maybe and change the Edge TTL that way?

Thanks!

The URL you posted would not be cached in the first place, as Cloudflare only caches static resources by default → https://developers.cloudflare.com/cache/about/default-cache-behavior

You’d need a page rule in order to cache HTML as well. In a page rule you could also specify a maximum time for which Cloudflare will cache it, but you’ll never have a guarantee that it will be cached for that time and Cloudflare could evict it from the cache at any time.

1 Like

Gotcha - so I could define the page-rule as something like (??):

URL: example.com/article/*

Cache Level: Cache Everything
Browser Cache TTL: 1 hour
Edge Cache TTL: 1 hour

I guess my question is, can anything be done at the origin to make the cache settings vary by article? So if article 1 I KNOW will not expire for 4 hours, vs article 2 will expire in 1? Would I need to remove the Browser/EdgeCache settings and set those in the Cache-Control header?

I was hoping I could return something during the origin pull to tell Cloudflare what I needed it to do.

If this matter, domain is on the pro plan.

Keep in mind that Cache TTL is the maximum amount of time a resource will be cached. Unused resources will be evicted early.

Here’s a blog post on setting cache control headers at the origin:

1 Like

Sort of, yes.

Not really, you can prevent the caching but you cannot change for how long Cloudflare will cache. As mentioned earlier, Cloudflare could even evict resources from the cache a lot earlier.

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