Answers.Body: <p>In the upcoming Craft 2.2 release, we've added a <code>using key</code> parameter to the <code>{% cache %}</code> tag for for situations like this.</p>
  
  <p>So you'd be able to do something like this for per user caching:</p>
  
  <pre><code>{% cache using key "myImportantUserCache" ~ currentUser.id %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-22T18:13:47.117Z
Answers.Text: Have I told you lately, that I love you?
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-22T18:22:20.583Z
Answers.Text: Not since last night! <wink>
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-24T11:34:20.647Z
Answers.Text: Awesome, I've been waiting for this! :)
Answers.UserDisplayName: André Elvan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-22T18:12:33.673Z
Answers.LastActivityDate: 2014-08-22T18:12:33.673Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>You could add user dependent content in between your <code>cache</code> 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):</p>
  
  <pre><code>{% cache %}
      &lt;div class="hidden"&gt;{{ currentUser.id }}&lt;/div&gt;
  {% endcache %}
  </code></pre>
  
  <p>.</p>
  
  <p>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 <a href="https://craftcms.stackexchange.com/q/2059/125">comment</a><sup>1</sup>).</p>
  
  <p>For the pages in question, add user specific info to the URL in your links:<br>
  <code>&lt;a href="/{{ currentUser.id }}/blog/{{ entry.slug }}"&gt;{{ entry.title }}&lt;/a&gt;</code></p>
  
  <p>and then use <a href="http://buildwithcraft.com/docs/routing#dynamic-routes" rel="nofollow noreferrer">dynamic routes</a> to make them work:<br>
  URI format:<code>&lt;*&gt;/blog/&lt;*&gt;</code> → Template: <code>blog/_entry.html</code></p>
  
  <p>.</p>
  
  <p><sup>1: "The cache, by default will cache it's contents on a per URL and per locale basis."</sup></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-22T10:47:00.970Z
Answers.LastActivityDate: 2014-08-22T10:47:00.970Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: carlcs
Body: <p>Is there a way to cache content with the (% cache %} tag on a per-user base?</p>
  
  <p>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.</p>
  
Tags: <users><cache>
Title: How to cache content per user?
ThreadText: # How to cache content per user?
  
  (Asked by: username_0 on 2014-08-22)
  
  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.
  
  **Tags:** users, cache
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-08-22. Score: 4 | Accepted answer
  
  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 %}
  
  ```
  
  > **Comments:**
  > **username_0**: Have I told you lately, that I love you?  
  > **username_1**: Not since last night! <wink>  
  > **username_2**: Awesome, I've been waiting for this! :)  
  
  ---
  
  ### Answer by username_3 on 2014-08-22. Score: 1
  
  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 username_1's [comment](https://craftcms.stackexchange.com/q/2059/125)1).
  
  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](http://buildwithcraft.com/docs/routing#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."
  
  
  ---
  
  