views:

621

answers:

3

I am running Django (1.0.2) on Google App Engine, and would like to know which (if any) of the following Django caching modules ought to inherently work with Google's memcache implementation:

Middlewear

  • django.middleware.cache.UpdateCacheMiddleware

  • django.middleware.common.CommonMiddleware

  • django.middleware.cache.FetchFromCacheMiddleware

Decorators

  • django.views.decorators.cache.cache_page

Template fragment caching

In a template:

{{ load cache }}{% cache 500 cache_name %}...cached...{% endcache %}

Low level API

  • django.core.cache


If some or all of these modules ought to work, are there any changes necessary to make them work properly, and are there any concerns or pitfalls ought one be aware of when using them?

I've perused the documentation and spent some time searching Google, but I haven't seen the answer to this. I suspect it may be a "turn-key" solution, but am wary of using the Django classes without at least one reference that someone else has done it without issue.

Thank you kindly.

+2  A: 

Running Django on Google App Engine says "it is possible to use nearly the entire Django stack on Google App Engine, including middleware." Also, that page has an example which includes one of the classes you asked about, so at least that one ought to work:

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
...

Various sites such as this one have code for using AppEngine and the Django caching code, such as django.middleware.cache.UpdateCacheMiddleware. See this Google search for other references, of varying quality. ;)

I haven't actually used this stuff, so I can only take others' word for it, but it does seem as though multiple people have done it.

Edit: Django tickets 7398 and 7399 are relevant to this.

aem
+4  A: 

No, app engine provides a custom memcached API. What you'll need to do (and there may already be an open source implementation of this, I don't know), is write a Django cache backend for this API, they're pretty simple, you can use the existing memcached backend as the basis for your new one: http://code.djangoproject.com/browser/django/trunk/django/core/cache/backends/memcached.py . http://code.google.com/appengine/docs/python/memcache/usingmemcache.html shows what the App Engine memcached API looks like.

Alex Gaynor
For the record, I think both of the answers given to this question are valuable. It was unclear how Stackoverflow would handle a tie in votes when the bounty ended, and I had hoped that it would split the bounty in the event of a tie. Unfortunately it seems to have arbitrarily chosen an answer and awarded all the bounty to it. Thank you for the reply, Lazypython, it was helpful and I appreciate it.
Brian M. Hunt
A: 

You should check this http://code.google.com/p/google-app-engine-django/

Luis