Clear Django view cache on logout -
i'm cacheing view below:
@cache_page(60 * 15) def my_view(request): # results request.user return httpresponse(json.dumps(results), content_type="application/json", status=200)
how can clear cache when user logs out?
you'll need define better cache key, changes on user or on user.is_authenticated. use key prefix if use redis redis allows removing keys stating prefix.
key = "result_{}".format(request.user.pk) results = cache.get(key) if not results: results = ... cache.set(key, results) ...
Comments
Post a Comment