In my system,there are many web servers
share one cache(memcache) server
.
Currently, it will clear all the data in memcache on every new deployment.
by running rake memcached:flush
What's more,I can saw the user session
in the cache server,
But every time, when I close the browser on my iPhone, I need to re-login again and again (I must get something wrong).
I set up my server in the back of AWS ELB
and auto scaling
How could I keep the users' session among every server behind ELB
To keep the user in logged status every they comes back.
cache server
| 8 | 2016-03-01 10:07:59 +0000 | 291 | _session_id:08f1d7e8e82055367c44372d431b7f23 |
| 8 | 2016-03-01 10:07:22 +0000 | 291 | _session_id:3553ad00c578b175d789f02dc696dd95 |
| 8 | 2016-03-01 10:04:22 +0000 | 291 | _session_id:5cc2302455981a8a5d3cea98deb80acb |
confi/initialize/session.rb (I save cache with Dalli and memcache)
Rails.application.config.session_store :cookie_store, key: '_sampleA_session'
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 6.month
view caches / model caches
- cache("common_header", skip_digest: true) do
- cache("footer", skip_digest: true) do
...
cache.rake (rake task)
require 'socket'
namespace :memcached do
desc 'Flushes whole memcached local instance'
task :flush do
server = ENV['MEMCACHE_DB']
port = 11211
command = "flush_all\r\n"
socket = TCPSocket.new(server, port)
socket.write(command)
result = socket.recv(2)
if result != 'OK'
STDERR.puts "Error flushing memcached: #{result}"
end
socket.close
end
end
production.rb
config.action_controller.perform_caching = true
config.cache_store = :dalli_store, ENV['MEMCACHE_DB'], { :pool_size => 10 ,compress: true }