2011-05-25 39 views
2

我想爲OmniAuth的商店使用Memcache,但我找不到有關如何執行此操作的任何示例。 Filesystem tmp不適用於我的主機。如何將下面的omniauth.rb中的代碼轉換爲使用Memcache。我是否還需要額外的寶石來讓Memcache工作?如何在Rails 3中使用帶有Memcache存儲的OmniAuth?

謝謝!

當前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 
+0

如果你的主機是Heroku,你只需要將'new('/ tmp')'改成'new('./tmp')' – 2011-07-30 02:36:52

回答

3

我猜你在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 

的Gemfile:

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

對不起,我知道這是一個痛苦。如果您找到更好的解決方案,請告訴我!

+0

真棒!這正是我的問題,這解決了這個問題,除非你現在可以使用omniauth gem,它與dalli集成,沒有問題https://github.com/intridea/omniauth – 2011-08-18 23:34:57

相關問題