Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango caching multi domain subdomain (wildcard) returning same content
    primarykey
    data
    text
    <p>I've got strange issue - I hope someone run similar problem before.</p> <p>I'm trying to cache content from different subdomains connected via wildcard to my django application 'example.com'.</p> <p>So when I get to subdomain1.example.com. i run differend code in view than excample.com - simple middleware for that like here: <a href="https://stackoverflow.com/questions/772050/django-caching-for-subdomains/1069854#1069854">Django caching for subdomains</a></p> <p>The thing is going wrong when I refresh simultonously pages form different domains (eg. using different tab browser). The result produce output of last refreshed page. And such behaviour do not depend on IP (if someone else is going onto some other subdomain in the same time you are entering main page you will get that subdomain content).</p> <p>If I wait for loading page first then i move to other everythins is loaded correctly :|</p> <p>If I turn off caching the problem does not exists.</p> <p>My soft spec:</p> <ul> <li>Ubuntu 8.04 LTS</li> <li>Apache + mod-wsgi <ul> <li>threads 10 processes not defined multiprocess=false</li> </ul></li> <li>Django 1.23</li> <li>file caching backend</li> </ul> <p>MIDDLEWARE:</p> <pre><code>class Subdomains: def process_request(self, request): u''' przekierowuje na stronę główną, jeżeli subdomena z której weszliśmy nie jest subdomeną miasta znajdującego się w bazie. Oraz ustawia zmienną request.META['city']! ''' city = get_city_from_host(request.get_host()) request.city=None if city: try: city = City.objects.filter(slug__exact=city) request.city=city[0].slug except: return HttpResponsePermanentRedirect(ROOT_URL) </code></pre> <p>VIEW:</p> <pre><code>def post_data(request,address,id): url_root = settings.ROOT_URL city_subdomain = request.city if city_subdomain: random_posts = Post.objects.filter(city__slug=city_subdomain).order_by('?') if random_posts.count() &lt;= 10: pass else: random_posts = random_posts[:10] city = City.objects.filter(slug__exact = city_subdomain)[0] try: post = Post.objects.get(id = int(id), city__slug__exact=city.slug) nearestinposts = post.nearestinpost_set.select_related(depth=2).all() return render_to_response('post_data.html', locals()) except: return HttpResponsePermanentRedirect('http://%s.%s/' % (city_subdomain, settings.ROOT_URL)) return HttpResponsePermanentRedirect('http://%s' % settings.ROOT_URL) </code></pre> <p>SETTINGS.PY</p> <pre><code>CACHE_BACKEND = 'file://%s/cache/' % PROJECT_DIR CACHE_MIDDLEWARE_SECONDS = 6000 CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True MIDDLEWARE_CLASSES = ( 'django.middleware.cache.UpdateCacheMiddleware', 'middleware.default.Subdomains', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware', ) </code></pre> <p>To modify CACHE_KEY i use hack: <a href="https://stackoverflow.com/questions/772050/django-caching-for-subdomains/1364942#1364942">Django caching for subdomains</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload