Users take sessions of other users when sessions are stored in memcached (Rails)

后端 未结 5 2187
眼角桃花
眼角桃花 2020-12-14 10:30

I have a very weird problem, when storing my session in Memcached. From time to time some users takes the session of others. E.g. John, becomes logged in as Maria, Maria as

5条回答
  •  星月不相逢
    2020-12-14 11:16

    Here it is the code that resolves the problem for me:

    I added these lines at the end of

    environment.rb

    if defined?(PhusionPassenger)
      PhusionPassenger.on_event(:starting_worker_process) do |forked|
        if forked
          CACHE.reset
          if Rails.cache.class == ActiveSupport::Cache::MemCacheStore
            Rails.cache.instance_variable_get(:@data).reset
          end
        end
      end
    end
    

提交回复
热议问题