cloudflare / templates

A collection of starter templates and examples for Cloudflare Workers and Pages
https://cloudflareworkers.com
MIT License
1k stars 638 forks source link

Edge Cache TTL #25

Closed michaelbourne closed 5 years ago

michaelbourne commented 5 years ago

I was wondering if the worker script could specify a TTL itself, or if a page rule would be more appropriate. Testing on some low traffic sites now and noticing that a cached response doesn't last long.

pmeenan commented 5 years ago

The edge caching worker already sets a 1-year expiration and relies on purging to clear it. If the content is sufficiently low-traffic I expect it is being automatically cleared from the edge independent of the TTL. Do you have a sense for how long "not long" is and do you know what edge you are hitting?

michaelbourne commented 5 years ago

Initial tests showed cache hits for up to 3 hours, then all misses at 24 hours. I'll try to dedicate some more time to figure out a more specific number. Low traffic would be under 10 uniques in that 24 hours.

For which edge, I was noticing that testing from various regions was producing misses on the first load, hits thereafter, leading me to believe that CF wasn't pushing the cached data to those pops as fast as I was hitting them. ( I could be wildly wrong about how that works though)

Also some local peering issues I believe, as I'm in Calgary, and I'm hitting the Seattle pop by default.

I set a global page rule to see if that would have any effect, I'll report back. greatly appreciate your work on this, I'm loving the results so far.

michaelbourne commented 5 years ago

I didn't come up with hard numbers on this, but it does appear to be traffic related. I have set up 3rd party services to crawl a couple pages daily from various regions and those regions all seem to keep a cached version in CF, whereas the regions with no traffic are almost always misses.

I'll sum this up to a non issue, since low traffic areas aren't a high concern, but high traffic areas are cached properly.