How does Cloudflare behave when cache is full?

I was just wondering what Cloudflare does when its cache is full and it’s unable to cache content anymore but receives the response from the origin server with a cache header?

E.g., Cloudflare receives a response from an origin server with the header Cache-Control: public, max-age=14400 but Cloudflare does not have enough space to store the response in the cache for you.

Will it then just not save the response in the cache? Is there a way to make Cloudflare evict the oldest cache and add the newest in such a case?

Cloudflare routinely evicts assets from the cache that haven’t been requested for a long enough time and a whole host of other factors - so there’ll always be space, but your response is also subject to being evicted if need be.

1 Like

Right, but there should be a limit for users to cache the data (I saw that it’s 512MB for Free, Pro, and Business customers)?

Let’s say I have 512 Mb of already cached data (and this data is frequently used, like every 10-15 seconds there’s a request to get the cached data) and then there comes an additional 1 Mb of data (that’s not been cached yet but asks to be cached). Will Cloudflare refuse to cache a new 1 Mb of data since there’s already 512 Mb of cached data that is being frequently used? Or will Cloudflare still find the least frequently used data out of that 512 Mb, evict it, and then cache a new 1 Mb of data?

This is on a per-file basis.

Maximum file size is 512 MB for Free, Pro, and Business customers and 5 GB for Enterprise customers.

The exacts will never particularly be public but is a good read on the logic behind it.

1 Like

That’s a good article, thank you!

Just to clarify a per-file basis term: if I want to cache images, does it mean that Cloudflare will cache images that are only <= 512 Mb? And there’s no limit on total files cached? (or at least, Cloudflare does tell). I’m wondering how Cloudflare manages to support a “no limit files” cache in terms of the cost but I guess that’s a question for another topic.

LRU eviction mostly I suppose - if your assets aren’t being used often enough to warrant their space then they will be evicted.

Egress is the killer for a lot of scenarios - if there’s a miss, Cloudflare has to go fetch your origin over the internet and you’re paying for egress fees on your origin. That’s why Cache Reserve is on the way:

That’s my understanding, yes. A single cached asset must be below your plan’s limit but that doesn’t mean all assets under your account must sum up to less than that limit.

1 Like

That’s correct but I don’t pay Cloudflare for that roundtrip to get data, I pay to the origin for the bandwidth. That’s what confused me in terms of the Cloudflare spendings and why they bill neither for cached data nor for their own bandwidth.

Same reason that R2 exists - egress is a lot cheaper than most providers would have you believe.

Of course, that ‘free’ bandwidth that even the Free plan has only goes so far and people hitting a lot of bandwidth would likely get a call about moving onto an Enterprise contract where the terms are a lot more flexible than the self-serve agreement.

1 Like

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