summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-01-03 21:22:01 +0100
committerDan McGee <dan@archlinux.org>2012-01-03 21:22:01 +0100
commit5a91a246a848248eb8ec9d9402791c34e5ca0f6b (patch)
tree3de37b4b8f3ecfd6c1d7cf390a3dfb469f8a6926
parent3b545d23b6ddb0ee843e9f792863615d69ceca5f (diff)
downloadarchweb-5a91a246a848248eb8ec9d9402791c34e5ca0f6b.tar.gz
archweb-5a91a246a848248eb8ec9d9402791c34e5ca0f6b.tar.xz
Remove all cache middleware
It's time to stop serving up stale pages. Remove this middleware caching and start pushing it down to spots where we can actually control it more appropriately (and only cache things that are expensive anyway). Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--main/middleware.py52
-rw-r--r--settings.py2
2 files changed, 0 insertions, 54 deletions
diff --git a/main/middleware.py b/main/middleware.py
deleted file mode 100644
index f417b54..0000000
--- a/main/middleware.py
+++ /dev/null
@@ -1,52 +0,0 @@
-# begin copy of stock Django UpdateCacheMiddleware
-# this is to address feeds caching issue which makes it horribly
-# unperformant
-
-from django.conf import settings
-from django.core.cache import cache
-from django.utils.cache import learn_cache_key, patch_response_headers, get_max_age
-
-class UpdateCacheMiddleware(object):
- """
- Response-phase cache middleware that updates the cache if the response is
- cacheable.
-
- Must be used as part of the two-part update/fetch cache middleware.
- UpdateCacheMiddleware must be the first piece of middleware in
- MIDDLEWARE_CLASSES so that it'll get called last during the response phase.
- """
- def __init__(self):
- self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
- self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
- self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False)
-
- def process_response(self, request, response):
- """Sets the cache, if needed."""
- if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache:
- # We don't need to update the cache, just return.
- return response
- if request.method != 'GET':
- # This is a stronger requirement than above. It is needed
- # because of interactions between this middleware and the
- # HTTPMiddleware, which throws the body of a HEAD-request
- # away before this middleware gets a chance to cache it.
- return response
- if not response.status_code == 200:
- return response
- # Try to get the timeout from the "max-age" section of the "Cache-
- # Control" header before reverting to using the default cache_timeout
- # length.
- timeout = get_max_age(response)
- if timeout == None:
- timeout = self.cache_timeout
- elif timeout == 0:
- # max-age was set to 0, don't bother caching.
- return response
- patch_response_headers(response, timeout)
- if timeout:
- response.content = response.content
- cache_key = learn_cache_key(request, response, timeout, self.key_prefix)
- cache.set(cache_key, response, timeout)
- return response
-
-# vim: set ts=4 sw=4 et:
diff --git a/settings.py b/settings.py
index a898381..a760ce8 100644
--- a/settings.py
+++ b/settings.py
@@ -67,7 +67,6 @@ TEMPLATE_LOADERS = (
# This bug is a real bummer:
# http://code.djangoproject.com/ticket/14105
MIDDLEWARE_CLASSES = (
- 'main.middleware.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
@@ -75,7 +74,6 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.middleware.doc.XViewMiddleware',
- 'django.middleware.cache.FetchFromCacheMiddleware',
)
ROOT_URLCONF = 'urls'