1

我正在将 Rails 3 应用程序转换为 Rails 4 应用程序,该应用程序active_record_store用于存储对于常规 cookie 来说太大的会话信息,该应用程序已弃用 active_record_store。我的 Rails 4 应用程序正在引发错误...

ActionDispatch::Cookies::CookieOverflow (ActionDispatch::Cookies::CookieOverflow):

这导致我切换到active_record_storeRails 3。如果我的会话信息超过允许的限制,我可以在 Rails 4 中做什么?

更新。我在本地机器上启动了 memcache 服务器,并在开发文件中这样配置它

config.cache_store = :mem_cache_store, 'localhost', '127.0.0.1:11211',
{:namespace => 'myapp123'}

在控制台中,当我执行 Rails.cache 时,它​​显示了这一点(后面跟着很多数据)

=> 真

>> Rails.cache
=> #<ActiveSupport::Cache::MemCacheStore:0x007f80ebe10500 @options={}, @data=#<Dalli::Client:0x007f80ebe0fd08 @servers=["localhost:11211"]

但是,当我运行应用程序时,我遇到了同样的错误

ActionDispatch::Cookies::CookieOverflow (ActionDispatch::Cookies::CookieOverflow):
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/cookies.rb:455:in `[]='
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/session/cookie_store.rb:109:in `set_cookie'
  rack (1.5.2) lib/rack/session/abstract/id.rb:350:in `commit_session'
  rack (1.5.2) lib/rack/session/abstract/id.rb:226:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  activerecord (4.0.0.rc2) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.0.0.rc2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.0.rc2) lib/active_record/migration.rb:369:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:373:in `_run__1963944942928963409__call__callbacks'
  activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0.rc2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0.rc2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0.rc2) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0.rc2) lib/rails/engine.rb:511:in `call'
  railties (4.0.0.rc2) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
4

2 回答 2

1

你能告诉我 config/initializers/session_store.rb 的内容吗,好像你还在使用那里的 cookie 存储。

定义缓存存储时,仍然需要更改 session_store

config.session_store = :mem_cache_store
于 2013-07-03T20:51:30.297 回答
1

如果您使用 cookie 存储,则只能在会话中存储 4kb。你有两个选择。

  1. 考虑减少您在会话中存储的信息。如果您在会话中存储模型对象,请将其更改为仅存储 id。

  2. 使用 mem_cache_store

    config.action_controller.session_store = :mem_cache_store

您还需要设置一个内存缓存服务器并将其配置如下:

config.cache_store = :mem_cache_store, 'localhost', '127.0.0.1:11211',
{:namespace => 'myapp123'}
于 2013-06-24T22:21:41.980 回答