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.
| 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 |
Rails.application.config.session_store :cookie_store, key: '_sampleA_session'
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 6.month
- cache("common_header", skip_digest: true) do
- cache("footer", skip_digest: true) do
...
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
config.action_controller.perform_caching = true
config.cache_store = :dalli_store, ENV['MEMCACHE_DB'], { :pool_size => 10 ,compress: true }
For your two view fragment caches you can do (docs):
expire_fragment("common_header")
expire_fragment("footer")
This should invalidate the cached fragment and therefore update values you read from the model in this fragment (since the fragment is rerendered). If this is what you mean with model cache you are good to go. If you want to clear the SQL query cache as well (although I do not know why you would want to do so, since Rails invalidates this automatically) you can refer to this blog post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With