0

在将 Python Dev Appserver 更新到 Google App Engine 1.7.6(使用 Python 2.7)后,我在使用 memcache 查看器时遇到了一些问题。

我的内存缓存似乎没有更新或不可读。我尝试使用应用程序引擎内存缓存查看器查看内存缓存,但是当我输入内存缓存密钥时出现错误。

当我刷新缓存时,一切都照常进行,直到需要再次读取内存缓存...

命中率和内存缓存大小正常增加,所以缓存中有一些东西。此外,当我恢复到应用引擎 1.7.5 时,一切正常。也许其他人遇到过这个问题?

当我输入 memcache 键时,我得到以下信息:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1536, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1530, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\admin_request_handler.py", line 80, in dispatch
    super(AdminRequestHandler, self).dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\memcache_viewer.py", line 145, in get
    values['value'], values['type'] = self._get_memcache_value_and_type(key)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\memcache_viewer.py", line 74, in _get_memcache_value_and_type
    except (pickle.UnpicklingError, AttributeError, EOFError, ImportError,
NameError: global name 'pickle' is not defined

我尝试在 main.py 中包含一个“导入泡菜”,但这是徒劳的。

我已经包含了一些我的代码示例,但希望这不是必需的,我希望它与应用程序引擎更新有关,而不是我的代码......

我的一些 main.py 文件:

#import pickle
from google.appengine.api import memcache
from google.appengine.ext import db

以及我如何处理 memcache 的示例函数:

def mc_get(key):
    a = memcache.get(key)
    if a:
        val = a
    else:
        val = None
    return val

def mc_set(key, val):
    memcache.set(key, val)

如果我想查询我的数据库中的用户,我使用:

def get_users(update=False):
    mc_key = 'USERS'
    entries = mc_get(mc_key)
    if update or entries is None:
        a = User.all()
        logging.error('DB---Q - Users')
        entries = list(a)
        memcache.set(mc_key, entries)
    return entries

更新:我在 Google\google_appengine\google\appengine\tools\devappserver2\admin\memcache_viewer.py 的 memcache_viewer.py 文件中添加了“import pickle”(这是一个错误吗??)

现在,当我输入 memcache 键时,我在 memcache 键输入字段下收到以下错误:错误获取用户:无法从缓存中检索值:没有名为 main 的模块

任何帮助将不胜感激,在此先感谢。

4

1 回答 1

0

我从旧的数据存储 API 更改为 NDB(更改代码有点麻烦)。自动缓存似乎已经解决了这个问题,这可能表明问题出在我的代码上,但仍然不能解释为什么在使用应用引擎 1.7.5 而不是 1.7.6 时一切正常。

如果有人有其他选择,我会删除这个答案,只是想我会发布我的进展,以防其他人遇到同样的问题。

于 2013-04-06T12:02:33.750 回答