J
J
JRazor2020-05-25 19:11:45
Django
JRazor, 2020-05-25 19:11:45

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

1 answer(s)
S
Sergey Tikhonov, 2020-05-26
@JRazor

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 question

Ask a Question

731 491 924 answers to any question