# Does mongrel work with memcached?

**URL:** <https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500>\
**Category:** Rails\
**Created:** [August 20, 2007, 11:07am UTC](https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500 "2007-08-20T11:07:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![innr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ec9cab/32.png) [@innr](https://www.ruby-forum.com/u/innr)\
**Post date:** [August 20, 2007, 11:07am UTC](https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500/1 "2007-08-20T11:07:10Z")

</div>

Hello,

Has anyone gotten memcached to work with a mongrel cluster before? I  
see  
numerous posts on the internet of people who can’t get this to work, and  
no  
one saying it does.

Do these two technologies work together?

(Note: I say mongrel cluster. I know memcached works with a single  
mongrel  
instance).

## -Iain

View this message in context:  
[http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12232426](http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12232426)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![innr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ec9cab/32.png) [@innr](https://www.ruby-forum.com/u/innr)\
**Post date:** [September 25, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500/2 "2007-09-25T23:02:09Z")

</div>

Interesting… are you using memcache-client or Ruby-MemCache to make  
your  
bridge?

-Iain

Keith D.-3 wrote:

> mongrel cluster and enabled memcached sessions in my environment.rb.
> 
> > ## numerous posts on the internet of people who can’t get this to work, and

–  
View this message in context:  
[http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12233843](http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12233843)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![innr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ec9cab/32.png) [@innr](https://www.ruby-forum.com/u/innr)\
**Post date:** [September 25, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500/3 "2007-09-25T23:02:31Z")

</div>

Hurm, that suggests its a configuration issue. Could I take a look at  
the  
memcache lines you added for environment.rb please?

I’m using the “vanilla” ones posted on many blogs. Tried with both  
clients  
to no avail. I’m currently reading through the verbose debug from  
Ruby-MemCache in the hope of spotting something…

-Iain

Keith D.-3 wrote:

> On 8/20/07, innr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Keith D.-3 wrote:
> > 
> > > mongrel cluster and enabled memcached sessions in my environment.rb.
> > > 
> > > > numerous posts on the internet of people who can’t get this to work,  
> > > > -Iain
> 
> >

–  
View this message in context:  
[http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12234130](http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12234130)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![innr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ec9cab/32.png) [@innr](https://www.ruby-forum.com/u/innr)\
**Post date:** [September 25, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500/4 "2007-09-25T23:07:16Z")

</div>

OK, I did some debugging of Rails, and I think the answer is to do with  
the  
way Rails uses sessions. The mem\_cache session store is actually  
serialised  
outside of the Rails framework, which means that it cannot instantiate  
ActiveRecord objects upon load. This is different to the file\_session  
storage which is part of Rails.

This means that if you store ActiveRecord objects in your session, there  
is  
a good chance your application will not work with memcached. I’m  
guessing  
you opt for the more traditional route and only store IDs in the  
session.

Different options at this point are to add additional extensions to the  
CGI:Session object (serialising everything as a string upon save and  
load)  
so that mem\_cache\_session will work, changing the application to use  
object  
IDs rather than objects in the session, or going back to file based  
sessions  
and adding some kind of mutex so they will work with mongrel clusters.

Thanks for all your help,  
-Iain

Keith D.-3 wrote:

> On 8/20/07, innr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Ruby-MemCache in the hope of spotting something…
> > 
> > > mac, works on
> > > 
> > > > bridge?  
> > > > didn’t
> > > > 
> > > > > On 8/20/07, innr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > > > > 
> > > > > > ## no
> > 
> > >
> 
> >

–  
View this message in context:  
[http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12250769](http://www.nabble.com/does-mongrel-work-with-memcached--tf4297581.html#a12250769)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![innr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ec9cab/32.png) [@innr](https://www.ruby-forum.com/u/innr)\
**Post date:** [September 25, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500/5 "2007-09-25T23:09:54Z")

</div>

I am using memcache-client.

Also, I am running the production boxes on linux but developing on a  
mac, works on  
both.

Keith

---

<div class="post-metadata">

**Author:** ![innr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ec9cab/32.png) [@innr](https://www.ruby-forum.com/u/innr)\
**Post date:** [September 25, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/does-mongrel-work-with-memcached/112500/6 "2007-09-25T23:03:03Z")

</div>

The only line I’ve added is to the Rails::Initializer.run block and it  
looks like  
this:

config.action\_controller.session\_store = :mem\_cache\_store

Keith
