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 ?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With