playframework中的对象会话

bar*_*oco 6 session playframework

如何在foreach用户会话中存储实例对象?

我有一个类来建模复杂的算法.该算法旨在逐步运行.我需要为每个用户实例化此类的对象.每个用户都应该能够逐步推进他们的实例.

nie*_*els 6

您只能将对象存储在缓存中.对象必须是可序列化的.在会话中,您可以将密钥(必须是String)存储到Cache.如果对象已从缓存中删除(与会话超时相同),请确保代码仍然有效.它在http://www.playframework.org/documentation/1.0.3/cache中有解释.希望能解决你的问题.


plu*_*ete 5

在会话中存储值:

//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);
Run Code Online (Sandbox Code Playgroud)

如果要使会话对象无效/清除

session.clear()
Run Code Online (Sandbox Code Playgroud)