Google App Engine如何跟踪httpsession销毁 [英] Google App Engine how to track httpsession destroy

查看:146
本文介绍了Google App Engine如何跟踪httpsession销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何使用GAE跟踪httpsession破坏?
我发现HttpSessionListener在GAE中无法正常工作,sessionDestroyed方法从未调用过。



更具体地说,我有一个存储的信息数据库,当用户登录到应用程序时,但如果某个用户处于非活动状态一段时间,我需要从db中删除此信息,如果sessionDestroyed方法在此类事件发生时将被调用,那么将很容易,因为现在我执行了cron作业每一分钟,工作查询所有这类数据在内存中处理的数据是不活动的并将其删除。但是这样做效率很低,我可以通过缓存优化它。但是,也许泰尔是一些其他优雅的方式。



任何想法都热烈appricated。 正如你所看到的,HttpSessionListener不适用于App Engine,所以这是不可能的。部分原因是App Engine应用程序在多台机器上运行多个实例,因此没有单个VM可以调用它。按照您所描述的方式运行常规清理脚本是实现此目的的最佳方式,但实际上没有理由每分钟运行一次 - 一天中的几次应该足够完美!


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.

解决方案

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!

这篇关于Google App Engine如何跟踪httpsession销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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