About the Template Fragment Caching without Invalidation

In a list view, if you make the fragment cache based on the modified_at date, you don't need to invalidate cache on post save. It will just create a new cache entry next time you access it after a save, and the old cache entries will expire after a timeout.

{% load cache %}

{% for post in page_obj %}
  {% cache 86400 post_list_item post.pk post.modified_at request.LANGUAGE_CODE %}
    {% include "posts/includes/post_list_item.html" %}
  {% endcache %}
{% endfor %}

Tips and Tricks Programming Templates Caching Django 6.x Django 5.2 Django 4.2 Memcached Redis Cache

Django/Python Consulting

If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.