Memcache reset on rails 2.3 with preload

Eric Wong normalperson at
Thu Mar 10 16:23:10 EST 2011

Troex Nevelin <list at> wrote:
> What is a right code for resetting memcache connection in after_fork for  
> Rails 2.3 with "preload_app true" on REE?
> The only configurations about memcache in my app are:
> config/initializers/session_store.rb:
> ActionController::Base.session_store = :mem_cache_store
> config/environment.rb:
> config.cache_store = :mem_cache_store

So that uses the memcache-client gem?  I seem to remember that (and
dalli) only connects when it's needed, but I suppose some apps use
memcached at load time.

The following should work, not the most elegant:

  before_fork do |server,worker|
    ObjectSpace.each_object(MemCache) { |mc| mc.reset }

An after_fork would probably send unnecessary messages to the memcached

> I tried:
> Rails.cache.reset
> But it fails to start, looks like this code is for Rails3 only

Hopefully somebody else knows a more elegant way to handle this.

Eric Wong

More information about the mongrel-unicorn mailing list