ruby-on-rails - 如何在 Rails 3 中将 OmniAuth 与 Memcache 存储结合使用?

标签 ruby-on-rails memcached omniauth

我想将 Memcache 用于 OmniAuth 商店,但我找不到任何有关如何执行此操作的示例。文件系统 tmp 不适用于我的主机。如何将下面的omniauth.rb 中的代码转换为使用Memcache。另外,我是否需要任何额外的 gem 才能让 Memcache 正常工作?

谢谢!!

当前的omniauth.rb:

require 'openid/store/filesystem'
Rails.application.config.middleware.use OmniAuth::Builder do    
    provider :open_id, OpenID::Store::Filesystem.new('/tmp'), {:name => "google", :domain => "https://www.google.com/accounts/o8/id" }
end

最佳答案

我猜你正在使用 Heroku,因为我也遇到了一些麻烦。我在 Heroku 上使用标准 Memcached 库时遇到了一些问题,尽管我现在不记得它们是什么了。我最终使用 Dalli相反,它在那里效果很好。

不幸的是,默认的 ruby​​-openid 无法与 Dalli 作为客户端一起使用,并且似乎不再主动维护。我有a fork这既解决了这个问题,也可以在 Gemfile 中使用。

无论如何,以下内容应该适合您:

初始化器:

require 'openid/store/memcache'

Rails.application.middleware.use OmniAuth::Builder do
  provider :open_id, OpenID::Store::Memcache.new(Dalli::Client.new), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end

gem 文件:

gem 'dalli', '1.0.2'
gem 'ruby-openid', :git => 'git://github.com/chanks/ruby-openid.git', :ref => '9ec3b76'

抱歉,我知道这很痛苦。如果您找到更好的解决方案,请告诉我!

关于ruby-on-rails - 如何在 Rails 3 中将 OmniAuth 与 Memcache 存储结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6130262/

相关文章:

NHibernate.Caches.EnyimMemcached,protobuf-net.Enyim 想要 Enyim.Caching 的冲突版本

php - 如何在 Xampp Mac 上安装 Memcached

ruby-on-rails - Rails + SQL Server : what to put in database. yml?

css - 基础文本网格

java - NullPointerException 在 Google App Engine LocalSErviceTestHelper 上调用 tearDown()

ruby-on-rails-3 - 事件模型 MassAssignmentSecurity 错误

ruby-on-rails - 使用 omniauth-google-oauth2 的 Google Oauth 登录经常失败

ruby-on-rails - 后处理无类错误

css - 生产服务器不显示图像

ruby-on-rails - 在 Mongo 数据库中克隆文档