On Wednesday 01 February 2006 09:10, Bram de Jong - MTG wrote: > Now, I have some questions about caching. Here goes: > > 1. how does one cache websites (with django) that have personalized > views for the users? I.e. there's lot's of thing like > > if(user has voted for this item) > display "hello <username> you voted <user_vote>/10 for this item" > else > display voting dropdown
If you use the SessionMiddleware, it automatically adds a 'Vary' header for the 'Cookie' HTTP header. This does 2 things - internally it uses the session cookie as part of the cache key (so different sessions effectively get there own cache) and also tells other web caches that the content varies depending on the cookie i.e. instructs them to do the same thing. So basically, this is handled for you if you use that middleware. > 2. does django automatically invalidate caches when objects, > displayed in the cached page, are changed? I.e. say a person votes > and you want to display the page with his new vote on it. This means > I should invalidate the cached page. Does django help me with this in > any way, or should it be done by the coder. No, it doesn't invalidate the cache, since it can't work out whether what has changed will affect the output of the page (at least, not without introducing a lot of overhead and tight coupling between the template system and the ORM). However, it never caches for POST requests, and only POST requests should have side effects. So for adding a vote, you should use a POST request and this will always return a fresh page, so this example should work out fine. Luke -- I never hated a man enough to give him his diamonds back. (Zsa Zsa Gabor) Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/