1

I'm using django 1.3 in my app. I need to organize caching, which satisfies following rules:

  1. using memcached as cache backend
  2. using @cache_page decorator in views, which I want to cache
  3. each non-authorized (anonymous) user sees cached version of the page (so django should deliver cached version of the page);
  4. for each authorized user django should generate new version of page (non-cached) and deliver it.

How I can do it? I tried using two decorators below the view:

@cache_page(108000)
@vary_on_cookie

but when I logged in, first I see the new data, when after updating the data (directly in database by using phpMyAdmin) I refresh the page and see previous content version.

Dmitry Belaventsev
  • 6,347
  • 12
  • 52
  • 75

1 Answers1

1

It is probably what you need https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-CACHE_MIDDLEWARE_ANONYMOUS_ONLY

jasisz
  • 1,288
  • 8
  • 9
  • this method has one "-": if I use this option = True, than pages for anonymous users are cached and for authorized users are not cached. but cache generated for anonymous shown for authorized (so, it's not generated for authorized, but shown). I want authorized users always receive actual (not cached) data. – Dmitry Belaventsev Sep 15 '12 at 11:25
  • Are you sure about this? You must remember it is per site caching, done by middleware and you must remove per view caching decorators to work with it. – jasisz Sep 15 '12 at 11:52