You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1.1 KiB

from django.db.models.signals import post_save, post_delete, m2m_changed
from django.dispatch import receiver
from utils.cache import invalidate_cache_patterns
from .models import (
PlaylistItem,
Podcast,
PodcastCategory,
PodcastCollection,
PodcastPlaylist,
PodcastPlaylistInCollection,
)
TARGET_MODELS = [
PodcastCategory,
PodcastCollection,
Podcast,
PodcastPlaylist,
PodcastPlaylistInCollection,
PlaylistItem,
]
def invalidate_podcast_cache():
"""
Invalidates all Redis cache keys for podcast API views.
"""
return invalidate_cache_patterns("*podcast_api*", "*podcast_list*")
@receiver(post_save)
@receiver(post_delete)
def clear_podcast_cache_on_save_or_delete(sender, instance, **kwargs):
if sender in TARGET_MODELS:
invalidate_podcast_cache()
@receiver(m2m_changed)
def clear_podcast_cache_on_m2m(sender, instance, action, **kwargs):
if action in ('post_add', 'post_remove', 'post_clear'):
if isinstance(instance, (Podcast, PodcastPlaylist, PodcastCollection, PodcastCategory)):
invalidate_podcast_cache()