caching and "hello username" on each page

3 views
Skip to first unread message

Bram - Smartelectronix

unread,
Jul 28, 2007, 11:04:20 AM7/28/07
to django...@googlegroups.com
hello everyone,


I would LOVE to use caching for both anonymous and logged in users, but
the problem is that every page on our site (http://www.splicemusic.com)
has the typical "hello username | log out | ..." at the top of each page.

Now, how can I possibly cache both anonymous and logged in users easily?
I'm guessing that I would need to add @vary_on_cookie before for each
and every view?


- bram

Nic James Ferrier

unread,
Jul 28, 2007, 12:16:40 PM7/28/07
to django...@googlegroups.com

If the username is the only thing you could store the username in a
cookie and have Javascript write it out. Then the page is completly
cacheable.

--
Nic Ferrier
http://www.tapsellferrier.co.uk

Doug B

unread,
Jul 30, 2007, 12:43:07 AM7/30/07
to Django users
You could also make your own render_to_response() function that
renders and caches the generic part of the page, and then passes that
in as a context for your base layout with the non-cacheable stuff like
the username. Or make some of the generic stuff tags that cache
themselves using the lower level cache api.

James Bennett

unread,
Jul 30, 2007, 12:56:05 AM7/30/07
to django...@googlegroups.com
On 7/28/07, Bram - Smartelectronix <br...@smartelectronix.com> wrote:
> I would LOVE to use caching for both anonymous and logged in users, but
> the problem is that every page on our site (http://www.splicemusic.com)
> has the typical "hello username | log out | ..." at the top of each page.

You might consider using finer-grained caching, so that you only cache
the things that are actually expensive to generate (e.g., complex
database lookups).

--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Reply all
Reply to author
Forward
0 new messages