Preserve session when clearing cache in memcached

I use memcached/dalli for caching purposes in Rails. I also use dalli_store as my session store.

The problem is, when I clear view cache, users will be logged out of my system automatically. I think this is because all data in memcached is cleared, so the session data are lost.

Is there a way to avoid this?


At the end I used Redis as session store instead.

gem 'redis-rails'

and specify it in session store type:

AppEx::Application.config.session_store :redis_store,

I can then use Memcached as pure cache and clearing it without affecting user login status.

This is also good because when using Memcached, users get kicked out when cache gets full. Now user sessions last much longer.


Rails.cache.clear clears all cache (no possibility to specify elements). If you want to clear specific elements from cache, you should use Rails.cache.delete(key) (hook up some conditional if you want it deleted in certain circumstances)


Why do you clear the cache again? There are eviction properties that you can set at the cache level if you want to evict certain stale data from the cache and yet maintain the session. I don't know if memcached has different eviction options available.

链接地址: http://www.djcxy.com/p/60570.html

上一篇: 使JSON Web令牌无效

下一篇: 在清除memcached中的缓存时保留会话