Scala和Lift以及失去它内容的SessionVar [英] Scala and Lift and SessionVar that loses it contents

查看:48
本文介绍了Scala和Lift以及失去它内容的SessionVar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Lift中有这样的SessionVar:

I have SessionVar like this in Lift:

object MyObject {
   object myVar extends SessionVar[Box[MyObject]](Empty)
}

然后我一次为myVar设置值:

Then I set value once for myVar:

 MyObject.myVar(Full(value))

我的问题是,一段时间(1-5分钟)后,myVar将失去其值,也就是说,它将再次具有值Empty.由于我一直在点击页面,因此这不是非活动状态.我的代码未将值设置为空.在这1-5分钟内,myVar将正常运行.日志中不包含任何相关消息.

My problem is that after some time (1-5 mins) myVar will lose its value, that is, it will have value Empty again. This is not due inactivity since I am clicking pages constantly. My code is not setting value to Empty. During this 1-5 mins the myVar will work correctly. The logs contain no related messages.

我试图将关闭方法添加到myVar,但是没有被调用.

I tried to add shutdown method to myVar, but it is not getting called.

 override protected def onShutdown(session: CleanUpParam): Unit = {
   Log.error("shutdown executed")
 }

我正在通过mvn jetty:run命令在码头运行Lift.我正在使用Lift的1.1-SNAPSHOT.我没有明确创建任何类型的Cookie或会话.

I am running Lift in jetty via mvn jetty:run command. I am using 1.1-SNAPSHOT of Lift. I am not creating explicitly any kind of cookie or session.

有什么想法吗?会话可能会过期或以某种方式失效,但是为什么以及由谁呢?

Any ideas what is happening? It could be that session expires or invalidates somehow, but why and by whom?

我什至尝试用(LiftRules.enableLiftGC = false)禁用liftGC,但这并没有影响.

I even tried to disable liftGC with (LiftRules.enableLiftGC = false) but that does not affect.

推荐答案

我认为问题在于单击鼠标左右时,您无意中创建了一个新会话.那可以解释为什么您没有收到会话关闭事件:旧的会话仍然存在,但是您不再使用它.我建议您打印出每个请求的会话ID,并查看其是否更改.

I imagine that the issue is that while clicking around, you are accidentally creating a new session. That would explain why you're not getting the session shutdown event: the old session still exists, but you're no longer using it. I suggest that you print out the session ID with each request and see if it changes.

由于会话cookie即将到期,或者由于您未对某些链接进行URL编码(请参阅HttpServletResponse.encodeURL),或者正在浏览应用程序的上下文路径之外,因此您可能会丢失会话.

You might be losing the session because the session cookie is expiring, or because you aren't URL-encoding some links (see HttpServletResponse.encodeURL), or because you are navigating outside your application's context path.

这篇关于Scala和Lift以及失去它内容的SessionVar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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