1👍
✅
You can invalidate cache by registering a signal handler for model.save
You can also live with the fact that users will see the stale content until the cache expiration (1 hour default) make sure he logged in user will not see the cached content, otherwise he will honk the edit was lost.
Hmmm my answer is a bit vague, but I just wanted to say: no, you don’t strictly have to invalidate cache at each edit, it is a choice between performance and content freshness.
One more nit: the preferred idiom for cache usage is:
entries_on_day = cache.get(key)
if entries_on_day is None:
entries_on_day = BlogEntry.objects.filter(...args..)
cache.set(key,entries_on_day)
You save one cache query
Source:stackexchange.com