Skip to content

Instantly share code, notes, and snippets.

@rafaelcaricio
Created November 2, 2010 18:08
Show Gist options
  • Save rafaelcaricio/660031 to your computer and use it in GitHub Desktop.
Save rafaelcaricio/660031 to your computer and use it in GitHub Desktop.
Middleware que atualiza o cache.
#!/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.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" % (settings.CACHE_KEY_PREFIX, request.get_full_path())
cache.set(key, response.content)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment