Clearing Cache

Created on Dec. 17, 2012, 7:04 p.m. by Hevok & updated by Hevok on May 2, 2013, 5:23 p.m.

For example to avoid that after logout the back button from the browser redirects to the previous page (it should redirect to the login page), the browser cache can be cleared by the following:

...
from django.views.decorators.cache import cache_control
...
@cache_control(no_cache=True, must_revalidate=True, no_store=True):
def view(request):
    ...

However, this means that all views need to be wrapped in that structure, and that none of those views will be catchable.

An alternative is to consider using @vary_on_cookie, which means that the cache will be specific to that user only for the current cookie value. A "logout" will clear the session cookies and thus renders the cache invalid.

delete.jpg

Tags: browser, rest, django, redirect
Categories: Tutorial, News, reST
Parent: Web Framework

Update entry (Admin) | See changes

Comment on This Data Unit