Opened 5 years ago

Closed 5 years ago

#30072 closed Bug (duplicate)

SiteManager.get_current() cache uses global variable instead of cache breaking multiple instance deployments.

Reported by: Luke Seelenbinder Owned by: nobody
Component: contrib.sites Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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

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

Change History (2)

comment:1 by Luke Seelenbinder, 5 years ago

Description: modified (diff)

comment:2 by Tim Graham, 5 years ago

Description: modified (diff)
Resolution: duplicate
Status: newclosed
Summary: get_current cache uses global variable instead of cache breaking multiple instance deployments.SiteManager.get_current() cache uses global variable instead of cache breaking multiple instance deployments.

Duplicate of #15894.

Note: See TracTickets for help on using tickets.
Back to Top