views:

72

answers:

3

Hi folks,

I've built a web application with Django, I'm using Memcached in order to cache data.

A few views cache the whole HttpResponse objects, therefore there might be a better alternative for returning the Memcached data other than going through Django.

What could be faster alternatives for returning Memcached data on HTTP Requests ?


I'm trying to make the operation as fast and lightweight as possible.

Help would be much appreciated! :)

+1  A: 

I don't believe there's a faster way to "cache/retrieve a whole Python object" (given that memcached stores strings) than cPickle's loads and dumps methods with a second argument of -1 (which tells cPickle to use the fastest, tightest algorithm available).

That's if you're using memcached directly; if you're using it as the backend of Django's own cache system, you can use it per-view, etc, and Django will handle the serialization (and more) on your behalf.

Alex Martelli
@Alex: thanks for this. I was thinking more about caching the text that is being requested rather than a Pickled HttpResponse object. So that any application could plug in and return the data.
RadiantHex
+2  A: 

It sounds like you're looking for some sort of proxying server which can take the cached page and serve it without going through Django at all. You might take a look at Varnish.

Daniel Roseman
+1  A: 

If you use nginx as a proxy server in front of Apache, you can use its memcached module to serve cached HTML output directly from memcached. This data can be created and put into memcached by Django. I do think that the nginx memcached module only supports one memcached server instance though. Here are a couple of links that show the principles:

http://weichhold.com/2008/09/12/django-nginx-memcached-the-dynamic-trio/

http://bretthoerner.com/blog/2008/oct/27/using-nginx-memcached-module-django/

Chris