# Caching front page depending on cookie

**URL:** <https://www.ruby-forum.com/t/caching-front-page-depending-on-cookie/195141>\
**Category:** NGINX\
**Created:** [September 17, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/caching-front-page-depending-on-cookie/195141 "2010-09-17T15:30:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [September 17, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/caching-front-page-depending-on-cookie/195141/1 "2010-09-17T15:30:11Z")

</div>

If a user is not logged in, the front page is exactly the same. I asked  
a question a while back and it worked for my scenario then:

[http://www.ruby-forum.com/topic/210602](http://www.ruby-forum.com/topic/210602)

That was when I had nginx on the front and apache on the back. I was  
using a proxy. Now I’m using fastcgi.

How can I say something like “If a cookie is not set, serve the cached  
page. Otherwise, pass to fast cgi”.

I’m using a more recent development version of nginx.

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [September 17, 2010, 3:57pm UTC](https://www.ruby-forum.com/t/caching-front-page-depending-on-cookie/195141/2 "2010-09-17T15:57:03Z")

</div>

On Fri, Sep 17, 2010 at 03:30:11PM +0200, Thomas Delonge wrote:

> I’m using a more recent development version of nginx.

location = / {  
fastcgi\_pass …  
fastcgi\_cache …  
fastcgi\_cache\_bypass $cookie\_NAME;  
fastcgi\_no\_cache $cookie\_NAME; # to not save response in  
cache  
}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [September 17, 2010, 4:11pm UTC](https://www.ruby-forum.com/t/caching-front-page-depending-on-cookie/195141/3 "2010-09-17T16:11:59Z")

</div>

Igor S. wrote:

> On Fri, Sep 17, 2010 at 03:30:11PM +0200, Thomas Delonge wrote:
> 
> > I’m using a more recent development version of nginx.
> 
> location = / {  
> fastcgi\_pass …  
> fastcgi\_cache …  
> fastcgi\_cache\_bypass $cookie\_NAME;  
> fastcgi\_no\_cache $cookie\_NAME; # to not save response in  
> cache  
> }
> 
> –  
> Igor S.  
> [Igor Sysoev](http://sysoev.ru/en/)

So where is it caching it? And how can I be sure I’ve set it up right to  
see if it’s serving the cached page? Thanks.

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [September 17, 2010, 4:19pm UTC](https://www.ruby-forum.com/t/caching-front-page-depending-on-cookie/195141/4 "2010-09-17T16:19:18Z")

</div>

On Fri, Sep 17, 2010 at 04:11:59PM +0200, Thomas Delonge wrote:

> > ```
> > fastcgi_no_cache $cookie_NAME; # to not save response in 
> > 
> > ```
> > 
> > cache  
> > }
> > 
> > –  
> > Igor S.  
> > [Igor Sysoev](http://sysoev.ru/en/)
> 
> So where is it caching it?

http {  
factcgi\_cache\_path /path/to/cache keys\_zone=CACHE:10m;

```
server {
    location = / {
       fastcgi_cache CACHE;
       ...

```

> And how can I be sure I’ve set it up right to  
> see if it’s serving the cached page? Thanks.

If you request with cookie “NAME” fastcgi\_cache\_bypass forbids to look  
up  
cache. You may log $cookie\_NAME and $upstream\_cache\_status variables  
to how requests are served.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
