From ce0bc1f7825d8f466ff0fcbe49a2715c6e7cb2a5 Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Wed, 22 Aug 2012 13:18:33 -0400 Subject: [PATCH] Separate caches per-domain-name --- common/djangoapps/util/cache.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/util/cache.py b/common/djangoapps/util/cache.py index 85b8ed3369..89b5dffd5e 100644 --- a/common/djangoapps/util/cache.py +++ b/common/djangoapps/util/cache.py @@ -9,6 +9,7 @@ from functools import wraps from django.core import cache + # If we can't find a 'general' CACHE defined in settings.py, we simply fall back # to returning the default cache. This will happen with dev machines. try: @@ -41,7 +42,10 @@ def cache_if_anonymous(view_func): def _decorated(request, *args, **kwargs): if not request.user.is_authenticated(): #Use the cache - cache_key = "cache_if_anonymous." + request.path + # same view accessed through different domain names may + # return different things, so include the domain name in the key. + domain = str(request.META.get('HTTP_HOST')) + '.' + cache_key = domain + "cache_if_anonymous." + request.path response = cache.get(cache_key) if not response: response = view_func(request, *args, **kwargs)