# Cache always shows expired status for anonymous users

**URL:** <https://www.ruby-forum.com/t/cache-always-shows-expired-status-for-anonymous-users/223830>\
**Category:** NGINX\
**Created:** [October 19, 2012, 4:21am UTC](https://www.ruby-forum.com/t/cache-always-shows-expired-status-for-anonymous-users/223830 "2012-10-19T04:21:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 19, 2012, 4:21am UTC](https://www.ruby-forum.com/t/cache-always-shows-expired-status-for-anonymous-users/223830/1 "2012-10-19T04:21:10Z")

</div>

I have my homepage cached as shown

location = / {

if (-f /var/www/statichtmls/during\_build.html) {

return 503;

}

set $country\_code $http\_x\_country\_code;

set\_if\_empty $country\_code $geoip\_country\_code;

limit\_req zone=pw burst=5 nodelay;

proxy\_pass [http://localhost:82](http://localhost:82);

proxy\_set\_header Host $host;

proxy\_set\_header X-Real-IP $remote\_addr;

proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

proxy\_set\_header X-Country-Code $country\_code;

proxy\_set\_header Accept-Encoding “”;

proxy\_ignore\_headers Cache-Control;

proxy\_ignore\_headers Expires;

proxy\_ignore\_headers X-Accel-Expires;

add\_header X-Cache-Status $upstream\_cache\_status;

proxy\_cache cache;

proxy\_cache\_key  
$scheme$host$request\_uri$cookie\_sessionid$country\_code;

proxy\_cache\_valid 200 302 2m;

proxy\_cache\_use\_stale updating;

}

But every time I hit the page as an anonymous user it shows

X-Cache-Status: EXPIRED

user$ curl -I [site.com](http://site.com)

HTTP/1.1 200 OK

Server: ngx\_openresty

Date: Fri, 19 Oct 2012 02:15:32 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

Keep-Alive: timeout=60

Vary: Accept-Encoding

Vary: Cookie

Set-Cookie: csrftoken=Dl4mvy4Rky7sfZwqek27hFrCXzWCi9As; expires=Fri,  
18-Oct-2013 02:15:32

GMT; Max-Age=31449600; Path=/

X-Cache-Status: EXPIRED

I want to cache it both for logged in and anonymous and it looks like  
the  
absence of session cookie is creating issues.

How do I cache the homepage correctly?

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 20, 2012, 11:43am UTC](https://www.ruby-forum.com/t/cache-always-shows-expired-status-for-anonymous-users/223830/2 "2012-10-20T11:43:11Z")

</div>

I realized my folly. Set-Cookie for csrf token is invalidating the  
cache!

- Quintin
