Rails sessions

B

Bauduin Raphael

Hi,

I wondered how sessions are stored in rails, and if it can be tailored.

I'm a cgikit user as everyone knows by now ;-) and I like the way how
this is abstracted: you can write your own session storing class and
tell your app to use it. Is this possible (or something similar) with
Rails? I looked at the doc but only saw a reference to a drb session
daemon. (did I miss the right place in the doc?)

The reason I'm interested in such a thing is that I thought (but I
didn't test it yet) that it would let me integrate cgikit (and possibly
rails) developments in an existing PHP application eg.

thanks.

Raph
 
F

Florian Gross

Bauduin said:
Hi,
Moin!

I wondered how sessions are stored in rails, and if it can be tailored.

As far as I know CGI::Session is used for this.
I'm a cgikit user as everyone knows by now ;-) and I like the way how
this is abstracted: you can write your own session storing class and
tell your app to use it. Is this possible (or something similar) with
Rails? I looked at the doc but only saw a reference to a drb session
daemon. (did I miss the right place in the doc?)

Have a look at cgi/session.rb in your ruby library directory -- there
should be two sample session types in there already. (FileStore and
MemoryStore)
thanks.
Raph

Regards,
Florian Gross
 
D

David Heinemeier Hansson

I'm a cgikit user as everyone knows by now ;-) and I like the way how
this is abstracted: you can write your own session storing class and
tell your app to use it. Is this possible (or something similar) with
Rails? I looked at the doc but only saw a reference to a drb session
daemon. (did I miss the right place in the doc?)

Rails uses CGI::Session and will take any store for that. By default it
uses the PStore, which is a file-based store that uses Marshal to allow
all kinds of objects in it. It's very easy to use and scale, but
unfortunately it's also quite slow. In some benchmarks I did, it was
responsible for a 50% speed decrease over other methods, such as the
MemoryStore.

You can specify another Store than the default in the dispatcher. Have
a look at vendor/railties/dispatcher.rb.

On that note, does anyone have a database store for CGI::Session? It
would be nice to ship that with Rails as an option.
--
David Heinemeier Hansson,
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://www.instiki.org/ -- A No-Step-Three Wiki in Ruby
http://www.basecamphq.com/ -- Web-based Project Management
http://www.loudthinking.com/ -- Broadcasting Brain
http://www.nextangle.com/ -- Development & Consulting Services
 
T

Tim Bates

David said:
On that note, does anyone have a database store for CGI::Session? It
would be nice to ship that with Rails as an option.

I already told you I'd send you my CGI::Session::ActiveRecordStore. See
off-list.

Tim.
 
C

Carl Youngblood

I'd like to see a Drb-based store, so that you could have the speed of
memory-based access along with the ability to have a dedicated session
server for seamless failover of webservers behind a hardware load
balancer.

Carl
 
D

David Heinemeier Hansson

I'd like to see a Drb-based store, so that you could have the speed of
memory-based access along with the ability to have a dedicated session
server for seamless failover of webservers behind a hardware load
balancer.

It's already there! ;)

Have a look in vendor/actionpack/cgi_ext -- there's both a server and a
client (Session store). Works great too and it's pretty fast.
--
David Heinemeier Hansson,
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://www.instiki.org/ -- A No-Step-Three Wiki in Ruby
http://www.basecamphq.com/ -- Web-based Project Management
http://www.loudthinking.com/ -- Broadcasting Brain
http://www.nextangle.com/ -- Development & Consulting Services
 
D

David Heinemeier Hansson

On that note, does anyone have a database store for CGI::Session? It
I already told you I'd send you my CGI::Session::ActiveRecordStore.
See off-list.

I apologies for my forgetfullness. Marvelous job, Bates. It'll
certainly make the upcoming 0.7.6 release!
--
David Heinemeier Hansson,
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://www.instiki.org/ -- A No-Step-Three Wiki in Ruby
http://www.basecamphq.com/ -- Web-based Project Management
http://www.loudthinking.com/ -- Broadcasting Brain
http://www.nextangle.com/ -- Development & Consulting Services
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top