proxy cache

Igor Sysoev is at rambler-co.ru
Tue May 19 17:44:49 MSD 2009


On Tue, May 19, 2009 at 03:39:59PM +0200, Micha?? Jaszczyk wrote:

> >> 1. proxy_cache_valid is set to 1h and upstream's response is valid for 2h.
> >
> > nginx will cache for 2h.
> >
> >> 2. proxy_cache_valid is set to 2h and upstream's response is valid for 1h.
> >
> > nginx will cache for 1h.
> >
> >> 3. proxy_cache_valid is set to 1h and upstream's response doesn't
> >> contain any caching hints.
> >
> > nginx will cache for 1h.
> 
> This just means that upstream's caching instructions are more
> important than proxy_cache_valid, right?

Yes, the order is

X-Accel-Expires
Expires/Cache-Control
proxy_cache_valid

However, you may ignore the headers using

proxy_ignore_headers  X-Accel-Expires Expires Cache-Control;

> >> What happens if the client sends "If-Modified-Since" header?
> >
> > This header does not send to backend, however, nginx may responses 304.
> 
> I'm not sure if I understand. Let's imagine some scenarios (I-M-S
> stands for If-Modified-Since, L-M stands for Last-Modified):
> 
> 1. Client sends I-M-S, Nginx has response in cache, cached response
> has L-M < I-M-S, Nginx sends 304.

Yes. Small note, by default nginx sends 304 only if L-M == I-M-S.
Controlled by if_modified_since [off|exact|before] directive

> 2. Client sends I-M-S, Nginx has response in cache, cached response
> has L-M > I-M-S, Nginx serves response from cache.

Yes.

> 3. Client sends I-M-S, Nginx doesn't have response in cache, sends
> request to upstream, upstream's L-M < I-M-S, Nginx stores response in
> cache and sends 304.

Yes.

> 4. Client sends I-M-S, Nginx doesn't have response in cache, sends
> request to upstream, upstream's L-M > I-M-S, Nginx stores response in
> cache and sends response from upstream.

Yes.

> Am I right?
> 
> Regards,
> 
> -- 
> Micha?? Jaszczyk


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list