Created
November 2, 2010 18:08
-
-
Save rafaelcaricio/660031 to your computer and use it in GitHub Desktop.
Middleware que atualiza o cache.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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