#30072: SiteManager.get_current() cache uses global variable instead of cache
breaking multiple instance deployments.
-----------------------------------+--------------------------------------
Reporter: Luke Seelenbinder | Owner: nobody
Type: Bug | Status: closed
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Tim Graham):
* status: new => closed
* resolution: => duplicate
Old description:
> I use the Sites framework extensively with a multiple instances of the
> application server deployment of Django. Because the sites framework uses
> a global to cache the current site, any update ''only'' affects whichever
> application server handled the update, leaving the outdated information
> cached on any other application servers.
>
> I would patch it to use the Django caching system instead of a global,
> but I'm not sure if that's the correct way to go about it.
>
> Relevant code:
> https://github.com/django/django/blob/master/django/contrib/sites/models.py#L103
>
> {{{
> #!python
> def clear_site_cache(sender, **kwargs):
> """
> Clear the cache (if primed) each time a site is saved or deleted.
> """
> instance = kwargs['instance']
> using = kwargs['using']
> try:
> del SITE_CACHE[instance.pk]
> except KeyError:
> pass
> try:
> del
> SITE_CACHE[Site.objects.using(using).get(pk=instance.pk).domain]
> except (KeyError, Site.DoesNotExist):
> pass
> }}}
New description:
I use the Sites framework extensively with a multiple instances of the
application server deployment of Django. Because the sites framework uses
a global to cache the current site, any update ''only'' affects whichever
application server handled the update, leaving the outdated information
cached on any other application servers.
I would patch it to use the Django caching system instead of a global, but
I'm not sure if that's the correct way to go about it.
Relevant code:
https://github.com/django/django/blob/b5fe97a34ea527d4254b58c2e828450e7c32157f/django/contrib/sites/models.py#L103
{{{
#!python
def clear_site_cache(sender, **kwargs):
"""
Clear the cache (if primed) each time a site is saved or deleted.
"""
instance = kwargs['instance']
using = kwargs['using']
try:
del SITE_CACHE[instance.pk]
except KeyError:
pass
try:
del
SITE_CACHE[Site.objects.using(using).get(pk=instance.pk).domain]
except (KeyError, Site.DoesNotExist):
pass
}}}
--
Comment:
Duplicate of #15894.
--
Ticket URL: <https://code.djangoproject.com/ticket/30072#comment:2>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/071.83f54c12a92a8e41b70080c91d16e8cd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.