Cache for all but employees

I have a django site where I want to use the "admin panel" at the top of each page without an administrator for employees. It will contain useful things like page editing tools, etc.

The problem comes from me using the @cache_page decorator on a lot of pages. If an ordinary user clicks on a page, the cached version appears without an admin panel (even for administrator users), and if an administrator first gets to the page, ordinary users see the admin panel.

I could tediously go through the templates by adding regional cache blocks, but there are many templates, and life is too short.

Ideally, there would be a way to tell caching to ignore cache requests / set of requests from admin users ... But I don't know how best to implement this.

How would you deal with this problem?

+4
source share
1 answer

I really did not tell you the whole truth. The only registered people are employees. All others are anonymous.

Digging up the cache middleware source (which @cache_page is @cache_page ) I found the CACHE_MIDDLEWARE_ANONYMOUS_ONLY setting!

I believe this should fix things for me.

0
source

Source: https://habr.com/ru/post/1305542/


All Articles