Reputation: 25567
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! :)
Upvotes: 1
Views: 426
Reputation: 352
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/
Upvotes: 1
Reputation: 599630
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.
Upvotes: 2
Reputation: 881745
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.
Upvotes: 1