Answer the question
In order to leave comments, you need to log in
Django/DRF view caching with cache clearing option?
Good day.
I tried here to set up caching for some views with the ability to clear the cache by handler (all sorts of post_save and others).
And I was amazed: from all that I found - everything is just terribly crutch
- Default cache_page - does not support deletion of normal at all
- easy-cache - caches, for the most part, only property
- django-cacheops - caches, for the most part, only instance or queryset (cache_view only works on paper, there is no deletion either)
In an attempt to find a caching view with invalidate, I was defeated.
What do you recommend to use? How to approach the issue?
Answer the question
In order to leave comments, you need to log in
django-cacheops is more focused on ORM level caching, but the invalidation is tricky there. In general, you can try to reuse ORM level invalidation with cached_as, but it will be confusing because logic and hard to support.
In fact, you will have to duplicate the automatically working ORM invalidation rules at the view decorator level, but manually. And to maintain consistency between these rules and how this view actually generates a response.
We settled on the fact that, if necessary, we facilitate the generation of DRF responses through values() and prefetch_related(), and left the invalidation where it works best - at the ORM level.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question