如何在GAE中有效实施会话?

时间:2021-07-12 23:13:38

I was wondering about implementing my own sessions (more for an exercise than anything else) for a GAE app I'm working ... at first I was thinking of using the datastore to store the session data. However, every time something needs to be added to the session 'bucket', it would require saving to the datastore. Obviously that's bad since we want to minimize our writes. Then I thought about using memcache ... seemed like a good idea but then we're faced with issues of possible session corruption due to memcache being "evicted through memory pressure" by Google. So does that mean we are left with only the following options:

对于我正在使用的GAE应用程序,我想知道实现我自己的会话(更多是为了练习而不是其他任何东西)......起初我正在考虑使用数据存储来存储会话数据。但是,每次需要将某些内容添加到会话“存储桶”时,都需要保存到数据存储区。显然这很糟糕,因为我们想要最小化我们的写入。然后我想到使用memcache ...似乎是一个好主意,但随后我们面临可能的会话损坏问题,因为memcache被“内存压力驱逐”谷歌。那么这是否意味着我们只剩下以下选项:

  1. Storing all session data in cookies
  2. 将所有会话数据存储在cookie中

  3. Writing all session data to datastore and memcache, and then only reading from memcache
  4. 将所有会话数据写入数据存储区和内存缓存区,然后只读取内存缓存区

Anyone have any other ideas?

有没有其他想法?

3 个解决方案

#1


3  

I suggest checking out (and contributing to) these three implementations of appengine sessions before rolling out your own:

我建议在推出自己的以下之前检查(并参与)这三个appengine会话的实现:

Your options look fine but choosing between them probably depends on the size of the session data in your application.

您的选项看起来很好,但在它们之间进行选择可能取决于应用程序中会话数据的大小。

#2


5  

UPDATE - 21 Mar 2011

更新 - 2011年3月21日

At the time of this answer app-engine-patch is discontinued and gaeutilities offer worst features than gae-sessions.

在此答案时,app-engine-patch已停止,并且gaeutilities提供的功能比gae-sessions更糟糕。

#3


0  

If you use web2py (version 1.46 or latter) sessions are on by default on GAE. This achieved by the following three lines of web2py code at the top of the scaffoling model:

如果您使用web2py(版本1.46或更高版本),则会在GAE上默认启用会话。这是通过脚手架模型顶部的以下三行web2py代码实现的:

from gluon.contrib.gql import *
db=GQLDB()
session.connect(request,response,db=db)

Here is a sample action that counts:

以下是一个重要的示例操作:

def index():
    session.c=session.c+1 if session.c else 1
    return dict(counter=session.c)

#1


3  

I suggest checking out (and contributing to) these three implementations of appengine sessions before rolling out your own:

我建议在推出自己的以下之前检查(并参与)这三个appengine会话的实现:

Your options look fine but choosing between them probably depends on the size of the session data in your application.

您的选项看起来很好,但在它们之间进行选择可能取决于应用程序中会话数据的大小。

#2


5  

UPDATE - 21 Mar 2011

更新 - 2011年3月21日

At the time of this answer app-engine-patch is discontinued and gaeutilities offer worst features than gae-sessions.

在此答案时,app-engine-patch已停止,并且gaeutilities提供的功能比gae-sessions更糟糕。

#3


0  

If you use web2py (version 1.46 or latter) sessions are on by default on GAE. This achieved by the following three lines of web2py code at the top of the scaffoling model:

如果您使用web2py(版本1.46或更高版本),则会在GAE上默认启用会话。这是通过脚手架模型顶部的以下三行web2py代码实现的:

from gluon.contrib.gql import *
db=GQLDB()
session.connect(request,response,db=db)

Here is a sample action that counts:

以下是一个重要的示例操作:

def index():
    session.c=session.c+1 if session.c else 1
    return dict(counter=session.c)