4

I have a django site where I want to stick an "admin bar" along the top of every non-admin page for staff members. It would contain useful things like page editing tools, etc.

The problem comes from me using the @cache_page decorator on lots of pages. If a normal user hits a page, the cached version comes up without the admin bar (even for admin users) and if an admin hits the page first, normal users see the admin bar.

I could tediously step through the templates, adding regional cache blocks but there are a lot of templates, and life is altogether too short.

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

How would you tackle this problem?

Oli
  • 235,628
  • 64
  • 220
  • 299
  • Not exactly the same problem, but similar: http://www.holovaty.com/writing/django-two-phased-rendering/ – Tomasz Zieliński Mar 30 '10 at 12:24
  • That is genius but it does look like a headache to implement. Looks like an excellent idea for high-volume pages that need personalising. – Oli Mar 30 '10 at 13:00

1 Answers1

0

I actually didn't tell you the entire truth.. The only logged in people are staff members. Everybody else is anonymous.

Digging through the cache middleware source (what @cache_page uses) I found the CACHE_MIDDLEWARE_ANONYMOUS_ONLY setting!

I believe this should fix things for me.

Oli
  • 235,628
  • 64
  • 220
  • 299
  • 1
    FYI - ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting was deprecated in Django 1.6, because apparently it was 'largely ineffective': https://docs.djangoproject.com/en/1.6/releases/1.6/#cache-middleware-anonymous-only-setting – Matt Austin Jun 06 '14 at 06:44