Memcache不在App-Engine-Patch中?

时间:2011-02-02 02:03:33

标签: google-app-engine memcached app-engine-patch python-memcached

我正在尝试使用以下代码将日期存储到内存缓存中:

from datetime import date
from google.appengine.api.memcache import Client

MEMCACHE_DATE_KEY = 'date'

client = Client()

def last_date():
    return client.get(MEMCACHE_DATE_KEY)

def new_date():
    client.set(MEMCACHE_DATE_KEY, date.today())

我收到此错误:

Traceback (most recent call last):
  File "manage.py", line 4, in 
    setup_env(manage_py_env=True)
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/aecmd.py", line 67, in setup_env
    patch_all()
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/appenginepatcher/patch.py", line 29, in patch_all
    patch_app_engine()
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/appenginepatcher/patch.py", line 520, in patch_app_engine
    db.Model._meta = _meta(db.Model, ())
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/appenginepatcher/patch.py", line 258, in __init__
    settings.INSTALLED_APPS
  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/utils/functional.py", line 269, in __getattr__
  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/conf/__init__.py", line 40, in _setup

  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/conf/__init__.py", line 73, in __init__

  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/utils/importlib.py", line 35, in import_module
  File "/Users/benji/Projects/share-renting-engine/settings.py", line 120, in 
    from ragendja.settings_post import *
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/ragendja/settings_post.py", line 98, in 
    check_app_imports(app)
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/ragendja/settings_post.py", line 63, in check_app_imports
    __import__(app, {}, {}, [''])
  File "/Users/benji/Projects/share-renting-engine/engine/__init__.py", line 5, in 
    if date.today() != last_date():
  File "/Users/benji/Projects/share-renting-engine/engine/utils/date.py", line 12, in last_date
    return client.get(MEMCACHE_DATE_KEY)
  File "/Users/benji/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/memcache/__init__.py", line 428, in get
    self._make_sync_call('memcache', 'Get', request, response)
  File "/Users/benji/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 86, in MakeSyncCall
    return stubmap.MakeSyncCall(service, call, request, response)
  File "/Users/benji/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 279, in MakeSyncCall
    assert stub, 'No api proxy found for service "%s"' % service
AssertionError: No api proxy found for service "memcache"

如何在app-engine-patch中使用memcache?

感谢您的时间。

1 个答案:

答案 0 :(得分:1)

看起来你正试图在导入时调用memcache。从堆栈跟踪来看,Django在设置App Engine环境之前会导入模块,因此在模块级别对App Engine服务的任何调用都将在开发服务器上失败。

将调用移动到从请求处理程序调用的函数内的memcache,它应该可以解决您的问题。