Google App Engine 如何跟踪 httpssession 销毁
有人知道如何用 GAE 跟踪 httpssession destroy 吗? 我发现 HttpSessionListener 在 GAE 中无法正常工作,并且 sessionDestroyed 方法永远不会调用。
更具体地说,当用户登录应用程序时,我有一个信息存储在数据库中,但是如果某个用户在一段时间内不活动,我需要从数据库中删除此信息,如果在这种情况下调用 sessionDestroyed 方法,这将很容易事件发生了,目前我做了每分钟运行一次的 cron 作业,该作业查询内存中所有此类处理的数据,其中数据处于非活动状态并将其删除。但这是非常低效的方法,我可以通过缓存对其进行优化。但也许还有其他一些优雅的方式。
任何想法都会受到热烈的欢迎。
anybody knows how to track httpsession destroy with GAE?
I've found that HttpSessionListener doesn't work properly in GAE and sessionDestroyed method never calls.
To be more specific I have an information that I store in database when user logins to the application, but if some user is inactive for some time I need to remove this info from db, that will be easy if sessionDestroyed method will be invoked when such event happens, as for now I did cron job which runs each minute, the job queries all data of this kind handles in memory which data is inactive and removes it. But this is very inefficient way to do this, I can optimize it with cache. But maybe thare is some other elegant way.
Any thoughts are warmly appricated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所观察到的,HttpSessionListener 不适用于 App Engine,因此这是不可能的。部分原因是 App Engine 应用程序在多台计算机上运行多个实例,因此没有单个虚拟机可以调用它。正如您所描述的那样,运行定期清理脚本是执行此操作的最佳方法,尽管实际上没有理由每分钟运行它 - 每天几次应该就足够了!
As you observe, HttpSessionListener doesn't work on App Engine, so this isn't possible. This is in part due to the fact that App Engine apps run multiple instances on multiple machines, so there's no single VM to invoke this on. Running a regular cleanup script as you describe is the best way to do this, though there's really no reason to run it every minute - a couple of times a day should be perfectly sufficient!