How long Cloudflare keeps cached files?


I was trying to understand how often Cloudflare gets rid of the cached HTML files in their nodes.
I was reading some information about it here and here but I don’t have it yet very clear.

They say that Cloudflare will respect your origin expires / cache control headers to calculate the Edge Cache TTL.

But how do I specify on my server the expires / cache control headers ?
Is it this on Apache’s htaccess file?

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 hour"
ExpiresByType image/jpeg "access 1 hour"
ExpiresByType image/gif "access 1 hour"
ExpiresByType image/png "access 1 hour"
ExpiresByType text/css "access 1 hour"
ExpiresByType text/html "access 1 hour"
ExpiresByType application/pdf "access 1 week"
ExpiresByType text/x-javascript "access 1 hour"
ExpiresByType application/x-shockwave-flash "access 1 week"
ExpiresByType image/x-icon "access 1 hour"
ExpiresDefault "access 1 week"

Should I use a bigger value if I do not expect those values to change in the short term?
Something like 8 days? So my clients won’t have to request data to my server for 8 days and instead get it from Cloudflare’s cache?

But… will Cloudflare respect those 8 days of Cache and keep a copy of those pages in their nodes for 8 days? (Sounds like a lot of space for them for their millions of sites.


Bump? Any answer?


Let me see what I can find about this.


Could anyone provide an update on this please?
Thank you.


The general rule on this is Cloudflare will keep files in cache for up to the length of time you specify. But the caveat is if it’s a seldom-used resource, it will be purged sooner than that. For return visitors, their browser should honor the cache setting and hold onto those resources longer than Cloudflare’s edge cache will.

Let’s see if @ryan heard back on this.


Thank you for your answer. That’s indeed how a caching proxy should behave but since CloudFlare has a free service I wonder if they really keep even assets with cache-control max-age headers set to one year for that period.


Edge Cache maxes out at 1 month. Again, same rules apply…resources are purged if not used frequently.


Seems reasonable. Thank you @sdayman I apreciate it.