# Different cache time for authentication & non auth users

**URL:** <https://www.ruby-forum.com/t/different-cache-time-for-authentication-non-auth-users/223867>\
**Category:** NGINX\
**Created:** [October 21, 2012, 5:18am UTC](https://www.ruby-forum.com/t/different-cache-time-for-authentication-non-auth-users/223867 "2012-10-21T05:18:07Z")\
**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 21, 2012, 5:18am UTC](https://www.ruby-forum.com/t/different-cache-time-for-authentication-non-auth-users/223867/1 "2012-10-21T05:18:07Z")

</div>

Hi all,

How can I set separate caching expiration time for authenticated and non  
auth users?

In my case the caching is set this way

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

proxy\_cache\_valid 200 302 2m;

proxy\_cache\_use\_stale updating;

The presence of session ID ensure separate cache pages for auth & non  
auth  
users.

But I want an experience where non auth users have a page cached for 1  
hour  
and auth users have a page cached for 2 mins.

How can I achieve this in Nginx? Can someone help?

FYI, this is under the same location directive.

- Quintin

---

<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 21, 2012, 1:39pm UTC](https://www.ruby-forum.com/t/different-cache-time-for-authentication-non-auth-users/223867/2 "2012-10-21T13:39:16Z")

</div>

Hi,

Can someone help? I dont want to end up using if case.

- Quintin
