Session management in Play!

2,398 views
Skip to first unread message

James Ducker

unread,
Oct 25, 2009, 9:50:26 PM10/25/09
to Play Framework Usergroup
Hi,

Does Play! implement any methods that are called whenever a session is created/destroyed?

Also, I know Play! advocates statelessness; to that end, would you advise dumping objects into Play's Cache rather than the session object? (I am basically trying to store a shopping cart alongside any session, but I don't want to persist anything to the db until a user actually starts the "check out" process).

Thanks,

James

Jean-Francois Poux

unread,
Oct 25, 2009, 10:06:33 PM10/25/09
to play-framework
Hi James,

A Play instance does not maintain session data, so it'll be hard to
know when a session is created (we could) and when it's destroyed (I
don't think we can). The entire session data lies in the session
cookie, so you can't put much data (4Ko) or sensible data in there.
Play will only ensure that session is not altered by a crypto check,
that's the server key you find your application.conf file. Should you
want to distribute your app over a cluster, the play instances will
only need to share this key.

So, you have to place your cart related data elsewhere. If you
consider it temporary until the cart is checked out, go for the cache.
If you consider that it's more persistant, go for a database model.
I'd choose solution 2 under standard uses cases. Solution 1 will also
work out of the box, you'll just have to deploy a memcached if in
clustered environment.

Regards,
Jean-Francois

James Ducker

unread,
Oct 25, 2009, 11:46:34 PM10/25/09
to play-fr...@googlegroups.com
Thanks for that; I'll have to think about whether I'd rather hammer the cache or the database, but that's more or less what I was expecting to do. Thanks for answering my basic questions, I'm coming from .NET, where some things work quite differently.

- James


2009/10/26 Jean-Francois Poux <jf....@gmail.com>



--
James Ducker
Web Developer
http://www.studioj.net.au
Reply all
Reply to author
Forward
0 new messages