6

我正在探索 Sinatra,我想使用会话,但我不希望它们存储在 Cookie 中,我发现 Rack::Session::Pool 效果很好。

现在我希望会话在一段时间后过期,但我不明白如何实例化 Rack::Session::Pool 并且他们在 Sinatra 中使用它。

任何线索?

4

2 回答 2

10

Sinatra 非常强大,来自 The Wicked Flea 的技巧没有奏效,但这确实有效:

use Rack::Session::Pool, :domain => 'example.com', :expire_after => 60 * 60 * 24 * 365

谢谢 !

于 2009-06-06T17:45:39.850 回答
5

在您的机架文件中:

%w(rubygems rack sinatra).each { |dependency| require dependency }
disable :run

require 'myapp'

sessioned = Rack::Session::Pool.new(
  Sinatra::Application,
  :domain       => 'example.com',
  :expire_after => 60 * 60 * 24 * 365 # expire after 1 year
)
run sessioned

要启动 runrackup app.ru或使用 Passenger 等。这应该将您的应用程序包装在会话池中并启用其功能。我不完全知道为什么它不需要像大多数其他中间件一样使用。

了解我根本没有测试过这个,我还没有需要会话池的东西。我是从 Rack::Session::Pool 的文档中写的,页面顶部有一个示例。所以,我也不能确切地告诉你如何使用它。

于 2009-06-06T17:24:56.653 回答