简体   繁体   English

Rails.cache.clear正在注销所有已登录的用户(清除会话)

[英]Rails.cache.clear is signing out all logged in users (clearing sessions)

While we were using FileStore as cache store and DalliStore as session store, we could run Rails.cache.clear and it would simply clear the cache with no problems in Sessions whatsoever. 当我们将FileStore用作缓存存储区并将DalliStore用作会话存储区时,我们可以运行Rails.cache.clear,它将简单地清除缓存,而在Sessions中没有任何问题。

Now that we moved the cache store to mem_cache_store, if we run Rails.cache.clear we clear the cache but also sign out every user, destroying all sessions. 现在,我们将缓存存储区移到了mem_cache_store,如果运行Rails.cache.clear我们将清除缓存,同时也注销每个用户,销毁所有会话。

Is this the intended behavior? 这是预期的行为吗?

@phoet was right on. @phoet是正确的。 In my initializers/session_store, config.session_store was set to CacheStore. 在我的初始值设定项/ session_store中,config.session_store设置为CacheStore。 That's not the default in Rails 4, which is :cookie_store. 这不是Rails 4中的默认值::cookie_store。

What is confusing (and now I see the light) is this: no matter what cache store mecanism you choose, there will always be a cookie stored in the browser (with the name you set in that same file, right after the store mecanism, in the key: 'xxx' option - this key is actually the cookie name and has nothing to do with the key you set in secrets.yml to encrypt it). 令人困惑的是(现在我明白了):无论您选择哪种缓存存储机制,在存储机制之后,浏览器中始终会存储一个cookie(使用您在该文件中设置的名称),在密钥:“ xxx”选项中-该密钥实际上是cookie名称,与您在secrets.yml中设置的用于加密的密钥无关)。

If you use the default store mecanism (:cookie_store), the entire "session hash" will be stored in the cookie, and nothing on the server (database/memcached). 如果您使用默认的存储机制(:cookie_store),则整个“会话哈希”将存储在cookie中,而服务器上将不存储任何内容(数据库/内存缓存)。 Everything will be read and written directly in that cookie (which starting in Rails 4 is always encrypted if you set secret_key_base). 所有内容都将直接在该cookie中读取和写入(如果您设置secret_key_base,则从Rails 4开始始终对其进行加密)。

If you use any other storage (like CacheStore or ActiveRecordStore), the cookie will still be there, with the same name you set in the 'key' option, BUT it if you decoded it (you need the secret_key_base for that, google for decoding rails 4 session) you'll see will only contain the session ID, and then Rails will look for the data corresponding to that session either in the database (ActiveRecord) or memcached (CacheStore, considering you are using memcached and not FileStore for storing cache, but that's another config). 如果您使用任何其他存储(例如CacheStore或ActiveRecordStore),则cookie仍将存在,其名称与您在'key'选项中设置的名称相同,但如果对其进行了解码,则将其保留(为此您需要secret_key_base,谷歌用于解码)您将看到的Rails 4会话)将仅包含会话ID,然后考虑到您使用的是memcached而不是FileStore来存储缓存,Rails会在数据库(ActiveRecord)或memcached(CacheStore)中查找与该会话相对应的数据,但这是另一个配置)。

So, since my session store was set to CacheStore, when I did Rails.cache.clear the cookie wasn't being deleted (that's on the client side of course), but when Rails got the session ID inside that cookie it couldn't find anything in memcached to match it with. 因此,由于我的会话存储设置为CacheStore,所以当我执行Rails.cache.clear时,cookie并未被删除(当然是在客户端),但是当Rails在该cookie中获得会话ID时,它无法在memcached中找到与之匹配的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM