How much can be stored in sessions?

How much can be stored in sessions? Can it hold model records and
their associations?

Jose

Hi Jose,

In theory, the amount you can store in a session is limited only by the
size of a “text” field in the underlying database (usually gigabytes)
if you are using ActiveRecord session storage; or the maximum size of a
file on your filesystem if you are using file storage of sessions.

And yes: you can store ActiveRecord objects in a session.

But in practice, I’ve had Rails throw “stack level too deep” errors
when I’ve had data in sessions that’s very deeply linked (i.e. objects
that contain links to other objects, that contain links to others etc.
etc.). I’ve learnt from bitter experience that sometimes it’s better
to store object IDs in the session and to fetch the objects back again
on the next request.

But as long as you don’t overkill it, you might find it works fine for
you.

– Urbanus
http://goldberg.240gl.org