Prakash Raman
Prakash Raman

Reputation: 13933

rack session resets/expires

Currently I am using enable :sessions for my sinatra webserver. But I need to move into a memory based session management

When I use Rack::Session::Pool, it runs although my session seems to expire on page reload, or even on a new Ajax Call being made.

Upvotes: 1

Views: 1168

Answers (2)

wmarbut
wmarbut

Reputation: 4685

Nick is correct about the threading issue that Passenger brings to light.

Redis is a great in-memory solution. It is incredibly lightweight. You can find out more here: http://redis.io/.

I use the Redis adapter for Rack::Session.

You can find more about it here: http://redis-store.org/redis-rack/

It is pretty easy. Just include gem redis-rack in your Gemfile and do this in your sinatra app

require 'redis-rack'
disable :sessions
use Rack::Session::Redis

Upvotes: 2

nictrix
nictrix

Reputation: 1483

If you are using Passenger or one of the other webservers, it's because a new thread gets created. If you reload on your page quickly you'll probably get expired sessions with a new thread being created (it's in memory on a specific webserver thread)

If you reload your page slowly it shouldn't expire the session because your still on the same webserver thread.

Upvotes: 2

Related Questions