Question

I need to add memcached to my django website. It's an authenticated website, where different users see different data on the same pages. Which are the best practices? I mean, to avoid users to see each other cached pages (information leak)...

I suppose i should use something like:

{% load cache %}
{% cache 500 sidebar request.user.username %}
    .. sidebar for logged in user ..
{% endcache %}

or:

@vary_on_cookie
def my_view(request):
    # ..

Which is the safest and better way?

Était-ce utile?

La solution

It's not the same thing at all, the {% cache %} template tag allows to cache a template fragment and that's used by the server, @vary_on_cookie decorator sets the Vary response header to Cookie, and that's used by the browser.

Also, you could do {% cache 500 sidebar request.user %} instead of specifying the username.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top