0

我正在尝试实现 Guido 发布的代码,作为对Avoiding Memcache 1M limit of values问题的回答。当我第一次加载页面并向内存缓存添加值时,一切似乎(?)都在工作,但是当我重新加载它并从内存缓存中检索值时,我收到了一个奇怪的错误:

Traceback (most recent call last):
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 194, in Handle
    for chunk in result:
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/appstats/recording.py", line 1036, in appstats_wsgi_wrapper
    result = app(environ, appstats_start_response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/appengineurlhere/mypythoncode.py", line 87, in get
    entitylist = retrieve("entitylist")
  File "/appengineurlhere/mypythoncode.py", line 53, in retrieve
    return pickle.loads(serialized)
  File "/base/python27_runtime/python27_dist/lib/python2.7/pickle.py", line 1382, in loads
    return Unpickler(file).load()
  File "/base/python27_runtime/python27_dist/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
KeyError: ':'

这是存储/检索代码:

def store(key, value, chunksize=750000):
    serialized = pickle.dumps(value, 2)
    values = {}
    for i in xrange(0, len(serialized), chunksize):
        values['%s.%s' % (key, i//chunksize)] = serialized[i : i+chunksize]
    memcache.set_multi(values)

def retrieve(key):
    result = memcache.get_multi(['%s.%s' % (key, i) for i in xrange(32)])
    serialized = ''.join([v for v in result.values() if v is not None])
    return pickle.loads(serialized)

这就是我使用它的方式:

try:
  entitylist = retrieve("entitylist")
except EOFError:
  entitylist = MyModel.all().fetch(None)
  store("entitylist", entitylist)

其他怪事:

  • 我在我的开发服务器上看不到这个;只是生产 App Engine 网站。(虽然我的开发服务器上的数据略有不同;我相信它们都适合标准的 1MB 内存缓存大小,生产数据更大。)
  • 当我在开发和生产管理面板上搜索“entitylist”时,App Engine 告诉我“没有这样的键”。然而,根据显示的内存缓存的总大小(这是我实现内存缓存的唯一地方),绝对看起来有些东西正在被缓存。

谁能指出我应该查看或修复的方向?

4

1 回答 1

0

您是否有一些旧的 MyModel 实例与 MyModel 的当前定义不匹配?如果存在无法识别或缺失的属性,则在酸洗时可能会出错。

于 2012-07-15T23:21:14.463 回答