# Caching: Expires takes precedence over max-age

**URL:** <https://www.ruby-forum.com/t/caching-expires-takes-precedence-over-max-age/236039>\
**Category:** NGINX\
**Created:** [August 1, 2013, 10:00am UTC](https://www.ruby-forum.com/t/caching-expires-takes-precedence-over-max-age/236039 "2013-08-01T10:00:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 1, 2013, 10:00am UTC](https://www.ruby-forum.com/t/caching-expires-takes-precedence-over-max-age/236039/1 "2013-08-01T10:00:40Z")

</div>

Hello, I have a trouble with nginx caching pages it shouldn’t cache. I  
have  
uwsgi\_cache enabled:

uwsgi\_cache\_path /tmp/cache levels=1:2 keys\_zone=django:1m;  
location /test {  
uwsgi\_pass unix:/tmp/uwsgi.sock;  
uwsgi\_cache django;  
}

nginx caches responses that have Expires header set in the future, even  
if  
Cache-Control says otherwise:

Expires: Fri, 02 Aug 2013 19:47:42 GMT  
Cache-Control: no-cache, must-revalidate, max-age=0

And rfc2616 says:

Note: if a response includes a Cache-Control field with the max-  
age directive (see section 14.9.3), that directive overrides the  
Expires field.

Happens on nginx 1.2.1 and 1.4.1. If I add “uwsgi\_ignore\_headers  
Expires;”  
to the nginx conf, the pages don’t get cached. Is there something wrong  
with  
my nginx or uwsgi response headers?

Posted at Nginx Forum:

> **[caching: Expires takes precedence over max-age](https://forum.nginx.org/read.php?2,241443,241443#msg-241443)**
>
> Hello, I have a trouble with nginx caching pages it shouldn't cache. I have uwsgi\_cache enabled: uwsgi\_cache\_path /tmp/cache levels=1:2 keys\_zone=django:1m; location /test { uwsgi\_pass unix:/tmp/uwsgi.sock; uwsgi\_cache django; } nginx

---

<div class="post-metadata">

**Author:** ![hippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b487fb/32.png) [@hippo](https://www.ruby-forum.com/u/hippo)\
**Post date:** [August 2, 2013, 2:01pm UTC](https://www.ruby-forum.com/t/caching-expires-takes-precedence-over-max-age/236039/2 "2013-08-02T14:01:03Z")

</div>

Hello!

On Thu, Aug 01, 2013 at 03:59:45AM -0400, hippo wrote:

> Cache-Control says otherwise:  
> Happens on nginx 1.2.1 and 1.4.1. If I add “uwsgi\_ignore\_headers Expires;”  
> to the nginx conf, the pages don’t get cached. Is there something wrong with  
> my nginx or uwsgi response headers?

As of now nginx treats both Expires and “Cache-Control: max-age”  
with equal precedence, and uses whichever comes first.  
X-Accel-Expires takes precedence over both of them.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
