Created
November 5, 2010 05:15
-
-
Save rafaelcaricio/663672 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.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