开发者

Returning content directly from memcache - Django / HTTP Server

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 开发者_JAVA百科fast and lightweight as possible.

Help would be much appreciated! :)


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.


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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜