Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is session.id in Play 2.0?

With Play 1.0 we had the session.getId() method to retrieve a unique session identifier.

The id was handy to prefix keys in the global cache.

Where is Play 2.0 session.id equivalent ?

like image 822
Olivier Refalo Avatar asked Feb 02 '23 08:02

Olivier Refalo


1 Answers

Since the session data is stored as cookies, there is no more session id with play 2.0. In fact there is no need for an identify token either, the session data is just passed along with every request leaving the server completely stateless.

However, you may still need an id should you need to store per user data in the global cache. For this purpose, use the code below

// Generate a unique id
String uuid=session("uuid");
if(uuid==null) {
    uuid=java.util.UUID.randomUUID().toString();
    session("uuid", uuid);
}

Session id? it sounds so Java EE anyways...

like image 70
Olivier Refalo Avatar answered May 18 '23 15:05

Olivier Refalo