Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object session in playframework

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.

like image 237
barroco Avatar asked Sep 06 '10 22:09

barroco


People also ask

What is a session object in Java?

The Session object. This interface is called the Session object. The Session object stores information about, or change settings for a user session. Variables stored in a Session object hold information about one single user, and are available to all pages in one application. Common information stored in session variables are name, id,...

What is a session in ASP?

ASP solves this problem by creating a unique cookie for each user. The cookie is sent to the user's computer and it contains information that identifies the user. This interface is called the Session object. The Session object stores information about, or change settings for a user session.

What is a session_onStart procedure?

A new user requests an ASP file, and the Global.asa file includes a Session_OnStart procedure A user requests an ASP file, and the Global.asa file uses the <object> tag to instantiate an object with session scope When does a Session End? A session ends if a user has not requested or refreshed a page in the application for a specified period.

When does a session start in ASA?

A session starts when: A new user requests an ASP file, and the Global.asa file includes a Session_OnStart procedure A value is stored in a Session variable A user requests an ASP file, and the Global.asa file uses the <object> tag to instantiate an object with session scope


2 Answers

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.

like image 64
niels Avatar answered Nov 15 '22 10:11

niels


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()
like image 24
plunchete Avatar answered Nov 15 '22 10:11

plunchete