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 I tried: Rails.cache.reset But it fails to start, looks like this code is for Rails3 only
I opt to use this gem: https://github.com/fauna/memcached I use the following settings in my environment: $memcached = Memcached::Rails.new(cache_server, :namespace => "os-", :tcp_nodelay => true, # disable nagle algorithm :no_block => true) # dont block on writes ActionController::Base.cache_store = :mem_cache_store, $memcached $session_memcached = Memcached::Rails.new(cache_server, :namespace => "os-", :tcp_nodelay => true, # disable nagle algorithm :no_block => true) ActionController::Base.cache_store :mem_cache_store, $memcached ActionController::Base.session_store = :mem_cache_store ActionController::Base.session_options[:cache] = $session_memcached in after_fork i have $memcached.reset $session_memcached.reset Clifton On Thu, Mar 10, 2011 at 11:16 AM, Troex Nevelin <list at mrtech.ru> 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 > > > I tried: > Rails.cache.reset > > But it fails to start, looks like this code is for Rails3 only > _______________________________________________ > Unicorn mailing list - mongrel-unicorn at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-unicorn > Do not quote signatures (like this one) or top post when replying >
Troex Nevelin <list at mrtech.ru> 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_storeSo 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 } end An after_fork would probably send unnecessary messages to the memcached servers.> I tried: > Rails.cache.reset > > But it fails to start, looks like this code is for Rails3 onlyHopefully somebody else knows a more elegant way to handle this. -- Eric Wong
I use: if Rails.cache.is_a?(ActiveSupport::Cache::MemCacheStore) Rails.cache.instance_variable_get(:@data).reset end Cheers, Lawrence> 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 > > > I tried: > Rails.cache.reset > > But it fails to start, looks like this code is for Rails3 only > _______________________________________________ > Unicorn mailing list - mongrel-unicorn at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-unicorn > Do not quote signatures (like this one) or top post when replying >
Eric, No, I''m using the "memcached" gem which has a binding for libmemcached (and is much faster than the memcache-client gem). The memcached gem has a compatibility wrapper (Memcached::Rails) which is made to be backwards compatible with memcache-client. Clifton On Thu, Mar 10, 2011 at 3:23 PM, Eric Wong <normalperson at yhbt.net> wrote:> Troex Nevelin <list at mrtech.ru> 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 } > ?end > > An after_fork would probably send unnecessary messages to the memcached > servers. > >> 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 > _______________________________________________ > Unicorn mailing list - mongrel-unicorn at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-unicorn > Do not quote signatures (like this one) or top post when replying >
On 03/11/2011 01:01 AM, Lawrence Pit wrote:> I use: > > if Rails.cache.is_a?(ActiveSupport::Cache::MemCacheStore) > Rails.cache.instance_variable_get(:@data).reset > endThanks a lot, that is exactly what I needed