Is there a way to cache content with the (% cache %} tag on a per-user base?
If user A is logged in, his content gets cached. User B logs in, but his content should not interfere with that of User A.
Is there a way to cache content with the (% cache %} tag on a per-user base?
If user A is logged in, his content gets cached. User B logs in, but his content should not interfere with that of User A.
In the upcoming Craft 2.2 release, we've added a using key parameter to the {% cache %} tag for for situations like this.
So you'd be able to do something like this for per user caching:
{% cache using key "myImportantUserCache" ~ currentUser.id %}
You could add user dependent content in between your cache tags to make the cache invalidate itself every time the page is requested by a new user. This probably doesn't help you much (but depends on the use case):
{% cache %}
<div class="hidden">{{ currentUser.id }}</div>
{% endcache %}
.
Another idea is to have user specific URLs. That'd work because each URL gets its own cache entry in the DB (see Brad's comment1).
For the pages in question, add user specific info to the URL in your links:
<a href="/{{ currentUser.id }}/blog/{{ entry.slug }}">{{ entry.title }}</a>
and then use dynamic routes to make them work:
URI format:<*>/blog/<*> → Template: blog/_entry.html
.
1: "The cache, by default will cache it's contents on a per URL and per locale basis."