Play 2.0中的session.id在哪里? [英] Where is session.id in Play 2.0?

查看:87
本文介绍了Play 2.0中的session.id在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Play 1.0中,我们具有session.getId()方法来检索唯一的会话标识符.

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

该ID便于在全局缓存中为键添加前缀.

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

Play 2.0 session.id在哪里等效?

Where is Play 2.0 session.id equivalent ?

推荐答案

由于会话数据存储为cookie,因此play 2.0不再包含会话ID.实际上,也不需要标识令牌,会话数据随每个请求一起传递,使服务器完全无状态.

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.

但是,如果您需要将每个用户数据存储在全局缓存中,则可能仍需要一个ID. 为此,请使用下面的代码

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);
}

会话ID?听起来如此,Java EE仍然如此...

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

这篇关于Play 2.0中的session.id在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆