Nginx proxy cache doesn't update cache-control max-age time!

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Nginx proxy cache doesn't update cache-control max-age time!

J.R.
This was driving me crazy and I think I've figured out the problem.

I started using the proxy cache (which is great, saves regenerating a
lot of dynamic pages), except a bunch of my pages expire at a very
specific time, at the start of the hour, and my cache-control /
expires headers reflect that, because that's when the data is updated.

I started noticing stale pages shortly thereafter. Watching the
headers I realized that the 'max-age' time wasn't decreasing like it
should be, thus pages would end up being cached by clients longer than
they should be as I guess browsers consider this the most 'modern'.

Is there a setting I'm missing, or is there a way to have nginx
dynamically update the max-age while still maintaining the proxy
cache?
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx proxy cache doesn't update cache-control max-age time!

Maxim Dounin
Hello!

On Mon, Apr 06, 2020 at 10:26:04AM -0500, J.R. wrote:

> This was driving me crazy and I think I've figured out the problem.
>
> I started using the proxy cache (which is great, saves regenerating a
> lot of dynamic pages), except a bunch of my pages expire at a very
> specific time, at the start of the hour, and my cache-control /
> expires headers reflect that, because that's when the data is updated.
>
> I started noticing stale pages shortly thereafter. Watching the
> headers I realized that the 'max-age' time wasn't decreasing like it
> should be, thus pages would end up being cached by clients longer than
> they should be as I guess browsers consider this the most 'modern'.
>
> Is there a setting I'm missing, or is there a way to have nginx
> dynamically update the max-age while still maintaining the proxy
> cache?

There is no Age header support in nginx as of now (relevant ticket
in Trac: https://trac.nginx.org/nginx/ticket/146).  If you want
pages to expire at a specific time regardless of intermediate
caching, consider using the "Expires" header.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx proxy cache doesn't update cache-control max-age time!

J.R.
In reply to this post by J.R.
> There is no Age header support in nginx as of now (relevant ticket
> in Trac: https://trac.nginx.org/nginx/ticket/146).  If you want
> pages to expire at a specific time regardless of intermediate
> caching, consider using the "Expires" header.

The 'age' header appears to be something else... What I'm talking
about specifically is part of the 'cache-control' header...

For example:  "cache-control: max-age=9848, public, must-revalidate"

Without max-age decrementing while in the nginx proxy cache, all
client will receive the same cached number until the cache is
refreshed.

Since the proxy cache is storing the cache time internally (so it
knows when a page expires from its cache), one would think there could
be some way to get the max-age value to be updated from that internal
data.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx proxy cache doesn't update cache-control max-age time!

Maxim Dounin
Hello!

On Mon, Apr 06, 2020 at 12:25:44PM -0500, J.R. wrote:

> > There is no Age header support in nginx as of now (relevant ticket
> > in Trac: https://trac.nginx.org/nginx/ticket/146).  If you want
> > pages to expire at a specific time regardless of intermediate
> > caching, consider using the "Expires" header.
>
> The 'age' header appears to be something else... What I'm talking
> about specifically is part of the 'cache-control' header...
>
> For example:  "cache-control: max-age=9848, public, must-revalidate"
>
> Without max-age decrementing while in the nginx proxy cache, all
> client will receive the same cached number until the cache is
> refreshed.

The Age header is the HTTP/1.1 way to decrement effective value of
max-age, see here:

https://tools.ietf.org/html/rfc7234#section-4.2.3

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx proxy cache doesn't update cache-control max-age time!

J.R.
In reply to this post by J.R.
> The Age header is the HTTP/1.1 way to decrement effective value of
> max-age, see here:
>
> https://tools.ietf.org/html/rfc7234#section-4.2.3

Interesting...

Well, I solved the issue by simply removing the 'max-age' portion from
the 'cache-control' header, keeping the other portion. Expiration is
handled strictly from the 'expires' tag, which seems to be valid
according to one of those RFC's. Testing things out and caching
expires exactly when it is supposed to! So happy I can keep the proxy
cache enabled now!
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx