does mongrel work with memcached?

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

Hi Iain,

I have a mongrel_cluster working with memcached, to be honest I didn't
even know there was an issue around this. I assumed that memcached was
more of a rails
issue than a mongrel one.

I haven't done anything magical in my config files, just created my
mongrel cluster and enabled memcached sessions in my environment.rb.

Keith

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

-Iain

Keith Davey-3 wrote:

I am using memcache-client.

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

Keith

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 Davey-3 wrote:

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

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 Davey-3 wrote: