Keep session while clearing cache in memcached

I use memcached / dalli for caching in Rails. I also use dalli_store as a session repository.

The problem is that when I clear the cache view, users automatically log out. I think this is due to the fact that all data in memcached is cleared, so session data is lost.

Is there any way to avoid this?

+4
source share
3 answers

In the end, I used Redis as a session repository.

 gem 'redis-rails' 

and specify it in the session storage type:

 AppEx::Application.config.session_store :redis_store, 

Then I can use Memcached as a clean cache and clear it without affecting the user login status.

This is also good because when using Memcached, users exit the game when the cache is full. Now user sessions last much longer.

+2
source

Rails.cache.clear clears the entire cache (there is no way to specify elements). If you want to clear certain items from the cache, you should use Rails.cache.delete(key) (include some conditionals if you want them to be deleted under certain circumstances)

0
source

Why are you clearing the cache again? There are eviction properties that you can set at the cache level if you want to strip certain obsolete data from the cache and still maintain a session. I don't know if memcached has various shutdown options.

0
source

Source: https://habr.com/ru/post/1481088/


All Articles