我非常需要我的用戶對象,所以我想我會將它存儲在緩存中。由於我不知道它何時從Cache中銷燬,所以我把它作爲interceptor
。所以我定義了下面的代碼:訪問會話在全球級
@Override
public Action<?> onRequest(Request request, Method actionMethod) {
// find the user based on the userId that is stored in the session
// scope.
String userId = session.get("user"); // does not work
User loggedInUser = (User) Cache.get(userId);
if (loggedInUser == null) {
loggedInUser = User.getUerById(userSyscode);
}
return super.onRequest(request, actionMethod);
}
我認爲我可以使用:
session.get("user");
但在我看來,像session
不能訪問從Global class
,我做錯了什麼?