gpt4 book ai didi

java - Google App Engine - 调用 getSession().invalidate();导致 App Engine 表现怪异

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:41:13 26 4
gpt4 key购买 nike

当我调用 hreq.getSession().invalidate(); 时,应用程序引擎速度大幅下降。我查看了 appstats,发现在没有进行数据库调用的页面上,它分别调用了 memcache.get 和 datastore.get 23 次。这些调用的堆栈跟踪显示它是从 getSession() 调用的。这只发生在生产服务器上。每次我向页面发出请求时,它都会进行大量内存缓存和数据存储调用。不过,当我重新启动浏览器时,这种减速现象就会消失。

当我更改代码以简单地将 session 的 isLoggedIn 属性设置为 false,而不是调用 hreq.getSession().invalidate(); 时,一切都是美好的。

作为测试,我没有使我的 session 无效,但我更改了浏览器 session cookie 的值,应用引擎表现出相同的行为。

这是应用引擎的错误吗?

最佳答案

getSession() 与内存缓存和数据存储交互并不奇怪。使用数据存储查看器查看 _ah_SESSION 实体。您会注意到这是一个 Blob,Blob 是 session 信息。看看this .

App Engine includes an implementation of sessions, using the servlet session interface. The implementation stores session data in the App Engine datastore for persistence, and also uses memcache for speed. As with most other servlet containers, the session attributes that are set with session.setAttribute() during the request are saved to the datastore at the end of the request.

如果您要使 session 无效,则需要创建一个新 session ,这需要与内存缓存和数据存储进行交互。

关于java - Google App Engine - 调用 getSession().invalidate();导致 App Engine 表现怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2936930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com