Skip to content

Instantly share code, notes, and snippets.

@aakashjsr
Created September 21, 2018 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakashjsr/eb294a040138d644a80898f607f5e3d4 to your computer and use it in GitHub Desktop.
Save aakashjsr/eb294a040138d644a80898f607f5e3d4 to your computer and use it in GitHub Desktop.
Listener to invalidate cache
from django.core.cache import cache
def clear_model_cache(sender, *args, **kwargs):
"""
Clears cached data of models on update or delete.
:param sender: Model Class triggering this signal.
:param args: extra arguments
:param kwargs: extra keyword arguments
:return: None
"""
from .models import Student
if Student.CACHE_KEY in cache:
cache.delete(Student.CACHE_KEY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment