# Memcached Question - Authenticated Users?

**URL:** <https://www.ruby-forum.com/t/memcached-question-authenticated-users/161507>\
**Category:** NGINX\
**Created:** [February 27, 2009, 12:39am UTC](https://www.ruby-forum.com/t/memcached-question-authenticated-users/161507 "2009-02-27T00:39:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [February 27, 2009, 12:39am UTC](https://www.ruby-forum.com/t/memcached-question-authenticated-users/161507/1 "2009-02-27T00:39:50Z")

</div>

Hello,

I’m looking at enabling the memcache module. One question - for any  
member who has logged in to my site, I don’t want to serve a cached  
copy of the page. It’s fine for anonymous users, however. Is this  
possible? If I store a login cookie on the client, would that work?

Thanks!

---

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [February 27, 2009, 2:41am UTC](https://www.ruby-forum.com/t/memcached-question-authenticated-users/161507/2 "2009-02-27T02:41:11Z")

</div>

Thanks, I’ll look at that -

And yes, I wouldn’t be using the cookie to actually determine  
logged-in state, it’s only for the purpose of determining whether or  
not it’s ok to serve cached content. . .

---

<div class="post-metadata">

**Author:** ![unclouded](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/6bbea6/32.png) [@unclouded](https://www.ruby-forum.com/u/unclouded)\
**Post date:** [February 27, 2009, 12:59am UTC](https://www.ruby-forum.com/t/memcached-question-authenticated-users/161507/3 "2009-02-27T00:59:45Z")

</div>

I’ve not used the memcache module, but in general, what you are asking  
should be possible using the following:

location / {  
set $logged\_in “no”;  
if ($http\_cookie ~\* “logged\_in=yes”) {  
set $logged\_in “yes”;  
}  
if ($logged\_in = “yes”) {  
proxy\_pass http://app\_server;  
break;  
}  
# otherwise, serve a cached page here  
}

I have tested something similar to this, but not this exact config.  
Also,  
note that this would be easy to spoof. (My $logged\_in variable and the  
cookie that sets it are used only to decide whether to serve a cached  
page  
– not to determine whether a user is actually logged in.)

Also note that my cookie check is simplified for the purpose of  
simplicity.  
If you need to read a cookie, see the example in the “if” documentation  
here: [http://wiki.codemongers.com/NginxHttpRewriteModule#if](http://wiki.codemongers.com/NginxHttpRewriteModule#if)
