Created
September 21, 2018 07:36
-
-
Save aakashjsr/eb294a040138d644a80898f607f5e3d4 to your computer and use it in GitHub Desktop.
Listener to invalidate cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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