#15894: SITE_CACHE does not invalidate in multiprocess environments
------------------------------------+------------------------------------
Reporter: German M. Bravo | Owner: nobody
Type: Bug | Status: new
Component: contrib.sites | Version: 1.3
Severity: Normal | Resolution:
Keywords: cache invalidation | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Comment (by Randle Taylor):
Replying to [comment:22 Sergei Maertens]:
> Adding some extra context for this - we're also being hit by this in the
current context of Docker containers. For High-Availability reasons, we're
running multiple replicas. A change only propagates to a single one, and
the other replicas need restarting.
>
> I'm considering monkey-patching the global to replace it with a dict-
like object that actually calls out to the caching framework instead.
Maybe the cache global/singleton should be pointed to by new setting?
Something like `SITES_CACHE = "django.contrib.sites.models.SITE_CACHE"`.
>
> The discussion on the mailing list referred to by Tim seems to have died
without any outcome.
I ran into the same issue related to multi-tenant Docker containers. What
I am doing is creating a simple monkey patch of SiteManager.get_current
that looks roughly like this:
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
def get_current_patch(self, request=None):
from django.conf import settings
if request is None:
site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
host = request.get_host()
if host not in SITE_CACHE:
SITE_CACHE[host] = self.latest("pk")
return SITE_CACHE[host]
SiteManager.get_current = get_current_patch
}}}
}}}
With the monkey patching being done in the first middleware that the
request hits. Each tenant should only have one Site defined and and I
just use the host name for the cache key. Seems to be working ok.
--
Ticket URL: <https://code.djangoproject.com/ticket/15894#comment:23>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.f667427e787d418aa405a33a2da8ad99%40djangoproject.com.