[Django]-Django Cache โ€“ Update when model changed

6๐Ÿ‘

โœ…

You could clear the cache after creating or updating the object using signal post-save signal

from django.db.models.signals import post_save
from django.dispatch import receiver

class Entry(models.Model):
    content = models.TextField()

# method for updating after entry save data
@receiver(post_save, sender=Entry)
def clear_cache(sender, instance, **kwargs):
    # call cache clear here

Another alternative is to overload the save method of the model and after saving it calls to cache clear

Leave a comment