Skip to content

Commit

Permalink
added memcached middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
jobscry committed May 7, 2010
1 parent 02fb594 commit 9d6ab5b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions utils/MemcachedMiddleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- mode: python; coding: utf-8; -*-
# http://bretthoerner.com/blog/2008/oct/27/using-nginx-memcached-module-django/

from django.conf import settings

KEY = getattr(settings, 'NGINX_CACHE_PREFIX', 'NG')

class NginxMemcacheMiddleWare:
def process_response(self, request, response):
path = request.get_full_path()

if request.method != "GET" \
or (path.startswith('/admin') and not request.user.is_anonymous()) \
or response.status_code != 200:
return response

# settings.NGINX_CACHE_PREFIX == 'NG', just like nginx.conf
key = "%s:%s" % (KEY, path)
cache.set(key, response.content)

return response

0 comments on commit 9d6ab5b

Please sign in to comment.