# Caching images with memcached

**URL:** <https://www.ruby-forum.com/t/caching-images-with-memcached/219054>\
**Category:** NGINX\
**Created:** [April 19, 2012, 2:32pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054 "2012-04-19T14:32:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [April 19, 2012, 2:32pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054/1 "2012-04-19T14:32:27Z")

</div>

Hi everyone,

I want to cache png images with memcached and serve with nginx.

I configured nginx and i could write images to memcached. When i try to  
read this images from cache with memcached client i can.

But when i try to read this images from nginx, broken images comes.

For example : I put byte array to memcached with 115832 bytes but when i  
try to read get 114940 bytes.

Anyone has idea?

Thanks

Posted at Nginx Forum:

> **[Caching images with memcached](https://forum.nginx.org/read.php?2,225508,225508#msg-225508)**
>
> Hi everyone, I want to cache png images with memcached and serve with nginx. I configured nginx and i could write images to memcached. When i try to read this images from cache with memcached client i can. But when i try to read this images from...

---

<div class="post-metadata">

**Author:** ![utahemre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3ec8ea/32.png) [@utahemre](https://www.ruby-forum.com/u/utahemre)\
**Post date:** [April 19, 2012, 2:45pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054/2 "2012-04-19T14:45:30Z")

</div>

Hi,

i want to do the same setup, could you give me your configuration so  
that i can see how it works?

thanks  
alex

---

<div class="post-metadata">

**Author:** ![utahemre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3ec8ea/32.png) [@utahemre](https://www.ruby-forum.com/u/utahemre)\
**Post date:** [April 19, 2012, 2:51pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054/3 "2012-04-19T14:51:43Z")

</div>

I did the configuration that is explained in this site;

> **[Francisco Souza: Killer Java applications server with nginx and memcached](http://f.souza.cc/2010/12/killer-java-applications-server-with.html)**
>
> Post showing how to configure a Java application server integrated with nginx and memcached.

Posted at Nginx Forum:

> **[Re: Caching images with memcached](https://forum.nginx.org/read.php?2,225508,225512#msg-225512)**
>
> Hi everyone, I want to cache png images with memcached and serve with nginx. I configured nginx and i could write images to memcached. When i try to read this images from cache with memcached client i can. But when i try to read this images from...

---

<div class="post-metadata">

**Author:** ![utahemre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3ec8ea/32.png) [@utahemre](https://www.ruby-forum.com/u/utahemre)\
**Post date:** [April 19, 2012, 3:41pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054/4 "2012-04-19T15:41:27Z")

</div>

Hello!

On Thu, Apr 19, 2012 at 08:31:48AM -0400, utahemre wrote:

> try to read get 114940 bytes.
> 
> Anyone has idea?

Usually it happens due to compressed content being put into  
memcached by a memcached client.

Maxim D.

---

<div class="post-metadata">

**Author:** ![utahemre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3ec8ea/32.png) [@utahemre](https://www.ruby-forum.com/u/utahemre)\
**Post date:** [April 19, 2012, 4:56pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054/5 "2012-04-19T16:56:43Z")

</div>

I focused same topic that you are said about.

I am using spymemcached client to write the cache and nginx read wrong  
data.

After your reply i tried to write with whalin memcached client and tried  
to read both spymemcached and nginx. Neither nginx nor spymemcached can  
read data from cache.

Does nginx have any configuration that i configure which memcached  
client nginx use? Or anyone know which memcached client can run with  
nginx properly?

Emre

Posted at Nginx Forum:

> **[Re: Caching images with memcached](https://forum.nginx.org/read.php?2,225508,225520#msg-225520)**
>
> Hi everyone, I want to cache png images with memcached and serve with nginx. I configured nginx and i could write images to memcached. When i try to read this images from cache with memcached client i can. But when i try to read this images from...

---

<div class="post-metadata">

**Author:** ![utahemre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3ec8ea/32.png) [@utahemre](https://www.ruby-forum.com/u/utahemre)\
**Post date:** [April 19, 2012, 6:02pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054/6 "2012-04-19T18:02:37Z")

</div>

Hello!

On Thu, Apr 19, 2012 at 10:56:21AM -0400, utahemre wrote:

> client nginx use? Or anyone know which memcached client can run with  
> nginx properly?

More or less any memcached client can work properly with nginx,  
you just need to figure out how to write raw data into memcached  
from your client, i.e. without compression, serialization and so  
on. In case of Perl clients it’s more or less default behaviour  
for all modules I know (Cache::Memcached, Cache::Memcached::Fast)  
as long as you write scalars to memcached. No idea about Java.

Maxim D.

---

<div class="post-metadata">

**Author:** ![utahemre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3ec8ea/32.png) [@utahemre](https://www.ruby-forum.com/u/utahemre)\
**Post date:** [April 25, 2012, 3:31pm UTC](https://www.ruby-forum.com/t/caching-images-with-memcached/219054/7 "2012-04-25T15:31:39Z")

</div>

Hi

My problem has been solved.

If i put any image to cache with java spymemcached client, nginx get  
broken images. After that i changed my java client to whalin memcached  
client.

Now i am putting images with java whalin memcached client and i can get  
images with nginx properly.

But here is a important trick. You have to set SanitizeKeys attribute  
in whalin memcached client to false.

Regards

Posted at Nginx Forum:

> **[Re: Caching images with memcached](https://forum.nginx.org/read.php?2,225508,225767#msg-225767)**
>
> Hi everyone, I want to cache png images with memcached and serve with nginx. I configured nginx and i could write images to memcached. When i try to read this images from cache with memcached client i can. But when i try to read this images from...
