Skip to content

Instantly share code, notes, and snippets.

@rafaelcaricio
Created November 5, 2010 05:15
Show Gist options
  • Save rafaelcaricio/663672 to your computer and use it in GitHub Desktop.
Save rafaelcaricio/663672 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
from django.core.cache import cache
from django.conf import settings
class NginxCacheMiddleware:
def process_response(self, request, response):
cacheIt = True
if request.user.is_authenticated():
cacheIt = False
if request.method != "GET":
cacheIt = False
for exp in settings.CACHE_IGNORE_REGEXPS:
if re.match(exp, request.get_full_path()):
cacheIt = False
if cacheIt:
key = "%s:%s:%s" % (settings.CACHE_KEY_PREFIX, request.get_full_path(), request.META['QUERY_STRING'])
cache.set(key, response.content, settings.CACHE_MIDDLEWARE_SECONDS)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment