Opened 5 years ago

Last modified 5 years ago

#30072 closed Bug

get_current cache uses global variable instead of cache breaking multiple instance deployments. — at Version 1

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 Luke Seelenbinder)

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

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 (1)

comment:1 by Luke Seelenbinder, 5 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top