# Memcached not caching

**URL:** <https://www.ruby-forum.com/t/memcached-not-caching/179798>\
**Category:** NGINX\
**Created:** [December 3, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/memcached-not-caching/179798 "2009-12-03T23:41:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhjheins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@rhjheins](https://www.ruby-forum.com/u/rhjheins)\
**Post date:** [December 3, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/memcached-not-caching/179798/1 "2009-12-03T23:41:50Z")

</div>

Currently I am testing nginx as a reverse-proxy/load ballencer and the  
basic setup is working perfect. But memcached is not caching any content

System: Ubuntu 9.10 server with nginx (from ubuntu repository) and  
memcached (from ubuntu repository)

I have three backend server presumed named server1, server2, server 3  
and the nginx server is called nginx\_test  
My nginx.conf:

user www-data;  
worker\_processes 2;

error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
use epoll;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;  
access\_log /var/log/nginx/access.log;  
sendfile on;  
server\_tokens off;  
upstream cluster {  
server server1 ip addr weight=1  
server server2 ip addr weight=1;  
server server3 ip addr weight=1;  
}  
server {  
listen nginxserver ip addr:80;  
server\_name nginx\_test;  
location / {  
expires max;  
set $memcached\_key $uri;  
default\_type text/html;  
memcached\_pass localhost:11211;  
error\_page 404 502 = @cache\_miss;  
}  
location @cache\_miss {  
proxy\_pass [http://cluster](http://cluster);  
proxy\_redirect off;  
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\_buffers 8 32k;  
}  
# requesting nginx status  
location /nginx\_status {  
stub\_status on;  
access\_log off;  
allow all;  
}  
}  
#gzip  
gzip on;  
gzip\_http\_version 1.0;  
gzip\_min\_length 1000;  
gzip\_buffers 16 8k;  
gzip\_comp\_level 5;  
gzip\_proxied any;  
gzip\_types text/plain text/css application/javascript  
text/javascript text/xml application/x-javascript;  
gzip\_disable “MSIE [1-6].(?!.\*SV1)”;  
}

restarting nginx gives no faults and when using the reverse\_proxy  
everything works but the memcached part is not resulting in faster  
loading of the pages. when I telnet into memcached en give the command  
stats it shows no cached objects:

Connected to 127.0.0.1.  
Escape character is ‘^]’.  
stats  
STAT pid 11415  
STAT uptime 1725  
STAT time 1259879709  
STAT version 1.2.8  
STAT pointer\_size 32  
STAT rusage\_user 0.008000  
STAT rusage\_system 0.024001  
STAT curr\_items 0  
STAT total\_items 0  
STAT bytes 0  
STAT curr\_connections 5  
STAT total\_connections 217  
STAT connection\_structures 8  
STAT cmd\_flush 0  
STAT cmd\_get 210  
STAT cmd\_set 0  
STAT get\_hits 0  
STAT get\_misses 210  
STAT evictions 0  
STAT bytes\_read 5947  
STAT bytes\_written 1588  
STAT limit\_maxbytes 171966464  
STAT threads 5  
STAT accepting\_conns 1  
STAT listen\_disabled\_num 0

Anny suggestions???

Posted at Nginx Forum:

> **[memcached not caching](https://forum.nginx.org/read.php?2,27843,27843#msg-27843)**
>
> Currently I am testing nginx as a reverse-proxy/load ballencer and the basic setup is working perfect. But memcached is not caching any content System: Ubuntu 9.10 server with nginx (from ubuntu repository) and memcached (from ubuntu repository) I...

---

<div class="post-metadata">

**Author:** ![rhjheins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@rhjheins](https://www.ruby-forum.com/u/rhjheins)\
**Post date:** [December 19, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/memcached-not-caching/179798/2 "2009-12-19T15:25:29Z")

</div>

Hello!

On Thu, Dec 03, 2009 at 05:37:49PM -0500, rhjheins wrote:

> Currently I am testing nginx as a reverse-proxy/load ballencer and the basic setup is working perfect. But memcached is not caching any content

nginx doesn’t store anything in memcached,  
it just uses memcached as another type of backend.

It’s up to you to store appropriate data…

[…]

> STAT cmd\_set 0

… and you obviously don’t.

If you want nginx to cache responses from backend - use  
proxy\_cache instead.

Maxim D.

---

<div class="post-metadata">

**Author:** ![rhjheins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@rhjheins](https://www.ruby-forum.com/u/rhjheins)\
**Post date:** [December 19, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/memcached-not-caching/179798/3 "2009-12-19T15:25:29Z")

</div>

On Dec 3, 2009, at 2:37 PM, rhjheins wrote:

> ```
> }
> location @cache_miss {
> stub_status on;
> gzip_proxied any;
> 
> ```
> 
> STAT curr\_items 0  
> STAT evictions 0  
> STAT bytes\_read 5947  
> STAT bytes\_written 1588  
> STAT limit\_maxbytes 171966464  
> STAT threads 5  
> STAT accepting\_conns 1  
> STAT listen\_disabled\_num 0
> 
> Anny suggestions???

The nginx memcached modules does not actually ever put anything in  
the cache for you. Your backend processes are responsible for  
populating the cache, nginx will just serve from memcached if an item  
already exists at that key.

Cheers-

Ezra Z.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rhjheins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@rhjheins](https://www.ruby-forum.com/u/rhjheins)\
**Post date:** [June 23, 2010, 4:45pm UTC](https://www.ruby-forum.com/t/memcached-not-caching/179798/4 "2010-06-23T16:45:32Z")

</div>

Hi,

Sorry for pumping this -kinda old topic- up, but I’m having the same  
issue as the original poster.  
After installing memcashed it’s running but not storing or caching  
data.

Yes I know nginx doesn’t store anything in memcashed -which is shame-  
but what I’m asking for here is how to get memcached to cache and store  
data? is there any kind of command or code or something?

I’ve googled for that but I couldn’t find a way to do that.

any help will be appreciated.

Thanks in Advance

P. S.: regarding the proxy\_cache in nginx I’m having trouble getting it  
work because cookies problem. it cached cookies and that causes a lot of  
troubles.

Posted at Nginx Forum:

> **[Re: memcached not caching](https://forum.nginx.org/read.php?2,27843,101586#msg-101586)**
>
> Currently I am testing nginx as a reverse-proxy/load ballencer and the basic setup is working perfect. But memcached is not caching any content System: Ubuntu 9.10 server with nginx (from ubuntu repository) and memcached (from ubuntu repository) I...
