views:

86

answers:

2

How I can store an instance object foreach user session?

I have a class to modeling a complex algorithm. This algorithm is designed to run step-by-step. I need to instantiate objects of this class for each user. Each user should be able to advance step by step their instance.

+1  A: 

To store values in the session:

//first get the user's session
//if your class extends play.mvc.Controller you can access directly to the session object
Session session = Scope.Session.current();
//to store values into the session
session.put("name", object);

If you want to invalidate / clear the session object

session.clear()
plunchete
But `object` should be a `String`, right?
isola009
Oh yes, Object must be a String
plunchete
Then isn't my solution
isola009
+2  A: 

You can only store the objects in the Cache. The objects must be serializable for this. In the session you can store a key (which must be a String) to the Cache. Make sure that your code still works if the object was removed from the cache (same as a session-timeout). It's explained in http://www.playframework.org/documentation/1.0.3/cache. Hope that solve your problem.

niels
Could you put me a use example?, thanks so much
isola009
Sorry I can't see what I could show in an example which is not documented in the referenced documentation.
niels

related questions