| 4 | |
| 5 | Relevant code: https://github.com/django/django/blob/master/django/contrib/sites/models.py#L103 |
| 6 | |
| 7 | |
| 8 | {{{ |
| 9 | #!python |
| 10 | def clear_site_cache(sender, **kwargs): |
| 11 | """ |
| 12 | Clear the cache (if primed) each time a site is saved or deleted. |
| 13 | """ |
| 14 | instance = kwargs['instance'] |
| 15 | using = kwargs['using'] |
| 16 | try: |
| 17 | del SITE_CACHE[instance.pk] |
| 18 | except KeyError: |
| 19 | pass |
| 20 | try: |
| 21 | del SITE_CACHE[Site.objects.using(using).get(pk=instance.pk).domain] |
| 22 | except (KeyError, Site.DoesNotExist): |
| 23 | pass |
| 24 | }}} |
| 25 | |