Commit ce0bc1f7 by Victor Shnayder

Separate caches per-domain-name

parent f065959f
...@@ -9,6 +9,7 @@ from functools import wraps ...@@ -9,6 +9,7 @@ from functools import wraps
from django.core import cache from django.core import cache
# If we can't find a 'general' CACHE defined in settings.py, we simply fall back # 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. # to returning the default cache. This will happen with dev machines.
try: try:
...@@ -41,7 +42,10 @@ def cache_if_anonymous(view_func): ...@@ -41,7 +42,10 @@ def cache_if_anonymous(view_func):
def _decorated(request, *args, **kwargs): def _decorated(request, *args, **kwargs):
if not request.user.is_authenticated(): if not request.user.is_authenticated():
#Use the cache #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) response = cache.get(cache_key)
if not response: if not response:
response = view_func(request, *args, **kwargs) response = view_func(request, *args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment