1👍
There are many cases you will need to delete the old cache. You will get them soon.
Regarding your issue, I assume that you just need to cover a case: invalidate cache after a post is added.
This is best approach for you:
- Using signal to detect when a post is added
- From django cache docs, it says that cache.delete(‘key’) should be enough. So just need to use it, and call a function to warm-up the cache if needed then.
Sample code
@receiver(post_save, sender=Post)
def invalidate_post_list_cache(sender, instance, **kwargs):
"""
This signal helps invalidate post list cache and warm-up cache
"""
cache.delete('key')
call_function_to_warm_up_cache()
There are only two hard things in Computer Science: cache invalidation and naming things – Phil Karlton
Source:stackexchange.com