# Fastcgi cache how-to cache for logged-in users and make it custom for each user

**URL:** <https://www.ruby-forum.com/t/fastcgi-cache-how-to-cache-for-logged-in-users-and-make-it-custom-for-each-user/223029>\
**Category:** NGINX\
**Created:** [September 19, 2012, 5:04pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-how-to-cache-for-logged-in-users-and-make-it-custom-for-each-user/223029 "2012-09-19T17:04:58Z")\
**Posts on this page:** 4\
**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:** [September 19, 2012, 5:04pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-how-to-cache-for-logged-in-users-and-make-it-custom-for-each-user/223029/1 "2012-09-19T17:04:58Z")

</div>

Hello,

Currently I’m doing cache using fastcgi\_cache for non-logged-in users,  
and  
using ( if + fastcgi\_no\_cache + fastcgi\_cache\_bypass ) to pass logged-in  
users directly to backend which is PHP-FPM.

this work good enough, but when PHP-FPM start hitting 500+ req/s the  
slow/load start.

So what i’m thinking about is to create a cache for logged-in users and  
each  
user has it’s own cached files, is that possible? if yes can you please  
provide me some tips about that. I’ve goggled a lot but nothing help  
with  
that.

the site running custom php cms with mysql and memcached and apc

Thanks.

Posted at Nginx Forum:

> **[fastcgi cache how-to cache for logged-in users and make it custom for each user](https://forum.nginx.org/read.php?2,230878,230878#msg-230878)**
>
> Hello, Currently I'm doing cache using fastcgi\_cache for non-logged-in users, and using ( if + fastcgi\_no\_cache + fastcgi\_cache\_bypass ) to pass logged-in users directly to backend which is PHP-FPM. this work good enough, but when PHP-FPM start...

---

<div class="post-metadata">

**Author:** ![Muse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@Muse](https://www.ruby-forum.com/u/Muse)\
**Post date:** [September 19, 2012, 5:31pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-how-to-cache-for-logged-in-users-and-make-it-custom-for-each-user/223029/2 "2012-09-19T17:31:17Z")

</div>

On 19 Set 2012 17h04 CEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and each user has it’s own cached files, is that possible? if yes  
> can you please provide me some tips about that. I’ve goggled a lot  
> but nothing help with that.

Use the session ID as part of the cache key. I have a drupal config  
that uses that:

[https://github.com/perusio/drupal-with-nginx/blob/master/map\_cache.conf](https://github.com/perusio/drupal-with-nginx/blob/master/map_cache.conf)

HTH,  
— appa

---

<div class="post-metadata">

**Author:** ![Muse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@Muse](https://www.ruby-forum.com/u/Muse)\
**Post date:** [September 19, 2012, 6:08pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-how-to-cache-for-logged-in-users-and-make-it-custom-for-each-user/223029/3 "2012-09-19T18:08:42Z")

</div>

## António P. P. Almeida Wrote:

> > 
> 
> HTH,  
> — appa
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Woow, It’s very useful tip,

Could you illustrate this in details .? , Also Does it need to change  
the  
way php cms run his own cookies .?

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,230878,230881#msg-230881](http://forum.nginx.org/read.php?2,230878,230881#msg-230881)

---

<div class="post-metadata">

**Author:** ![Muse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@Muse](https://www.ruby-forum.com/u/Muse)\
**Post date:** [September 19, 2012, 6:56pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-how-to-cache-for-logged-in-users-and-make-it-custom-for-each-user/223029/4 "2012-09-19T18:56:04Z")

</div>

On 19 Set 2012 18h07 CEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > this work good enough, but when PHP-FPM start hitting 500+ req/s  
> > > [https://github.com/perusio/drupal-with-nginx/blob/master/map\_cache.con](https://github.com/perusio/drupal-with-nginx/blob/master/map_cache.con)  
> > > f

> Woow, It’s very useful tip,
> 
> Could you illustrate this in details .? , Also Does it need to  
> change the way php cms run his own cookies .?

No I don’t think so. What may have to change is the regex in the map  
directive that captures the session ID. It depends on how is  
generated.

You just use something like that and then set the cache key:

## The cache key.

fastcgi\_cache\_key $cache\_uid@$host$request\_uri;

— appa
