from django.core.cache import cache
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver

from settings.models import Setting, SiteSettings


def clear_all_cache():
    cache.clear()


@receiver(post_save, sender=Setting)
@receiver(post_delete, sender=Setting)
@receiver(post_save, sender=SiteSettings)
@receiver(post_delete, sender=SiteSettings)
def clear_settings_cache_on_change(sender, instance, **kwargs):
    clear_all_cache()
