Use pre-existing age header for initial cache age

Hi there,

Is there any way to get Cloudflare to incorporate a pre-existing “Age” header when caching a response? This way, Cloudflare can start with an initial cache age?

I would like to cache files additionally in my origin server this way.

Thanks!

I believe, if you could create a Page Rule with the Origin Cache Control: On option being enabled having the Cache Level option set to Standard.

That way, if you setup correctly at your origin host / server, it would send the HTTP max-age header with the wanted value for the specific request (files), therefore Cloudflare would respect it “as-is”.

Hopefully I understood good your question?

I believe, if you could create a Page Rule with the Origin Cache Control option being enabled.

I already have this done. It doesn’t help with the initial age of the cache.

An initial age header? The server should only server one Age header, that that would be the duration (max-age). The cache itself tracks the age.

Are you saying you already have that resource cached at the origin, and you want to layer Cloudflare’s cache over that one? As you can imagine, that gets a bit tricky.

1 Like

An initial age header? The server should only server one Age header, that that would be the duration (max-age). The cache itself tracks the age.

I’m referring to Age - HTTP | MDN, even Cloudflare sends this for cached content.

Are you saying you already have that resource cached at the origin, and you want to layer Cloudflare’s cache over that one? As you can imagine, that gets a bit tricky.

That’s exactly what I want to do.

So you are using Varnish or similar as the Origin. If a file is emitted from Varnish with these headers:

Cache-Control: max-age=120
Age: 60

You want Cloudflare to cache the file for another 60 seconds before expiring it, not 120 seconds. Perhaps you have enough control in the Origin to send something like:

Cache-Control: max-age=120, s-maxage=($max-age - $age)
Age: 60

I think its a good idea, but I don’t know of a way to do it in CF natively.

3 Likes

That’s one possible solution, and probably the best I’ll get. Thanks.

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