I need a per user caching. The regular view caching does unfortunately not support user-based caching.
I tried the template fragment caching like this:
{% load cache %}
{% cache 500 "mythingy" request.user %}
... HTML stuff ...
{% endcache %}
but it's slow as hell.
Does anybody know a faster way to achieve what I need?
Thanks!
as of django >=1.7, using the cache_page along with vary_on_cookie decorators on your view should solve this.
something like this.
take note of the order of decorators as
vary_on_cookie
should be processed before it gets tocache_page
.The following is an improved version for the accepted solution does not consider the request parameters.
decorator_of_cache_per_user.py
I found the solution!
Here is this Portuguese code snippet which works like a charm!
The good thing is that I don't need to fiddle around my template code but can use a clean decorator!
Code is included below
For people using django rest framework and maybe others:
Usage: