[Answered ]-How we can get the updated data by refreshing the cache using the cache_page in DRF with the same route?

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:

  1. Using signal to detect when a post is added
  2. 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

Leave a comment