将 Rack::Session::Pool 与 Sinatra 一起使用

发布于 2024-07-22 13:00:07 字数 169 浏览 5 评论 0原文

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

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

有什么线索吗?

I'm exploring Sinatra and I want to use sessions but I don't want them to be stored in a Cookie, I found Rack::Session::Pool which works very well.

Now I want sessions to expire after a certain duration but I don't understand how to instanciate the Rack::Session::Pool and them use it in Sinatra.

Any Clue ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懒猫 2024-07-29 13:00:08

Sinatra 非常强大,《邪恶跳蚤》中的技巧不起作用,但这个起作用了:

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

谢谢!

Sinatra is quite powerful, the trick from The Wicked Flea didn't work but this did :

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

Thanks !

暗恋未遂 2024-07-29 13:00:08

在您的rackup文件中:

%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

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

请注意,我根本没有测试过这个,我还没有需要会话池的东西。 我从 Rack::Session::Pool 的 文档 中编写了此内容,页面顶部有一个示例。 所以,我也无法告诉你具体如何使用它。

In your rackup file:

%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

To launch run rackup app.ru, or use Passenger, etc. This ought to wrap your application in the session pool and enable its functionality. I don't entirely know why it doesn't need use like most other middleware.

Understand that I haven't tested this at all, I haven't had something that needed session pools yet. I wrote this from the documentation for Rack::Session::Pool, which had an example at the top of the page. So, I can't tell you exactly how to use it either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文