Answers.Body: <p>It turns out the cache-control headers weren't coming through at the end.</p>
  <p>I solved the problem by adding all the right headers.</p>
  <pre><code>Header set Cache-Control &quot;max-age=0, no-cache, no-store, must-revalidate&quot;
  Header set Pragma &quot;no-cache&quot;
  Header set Expires &quot;Wed, 12 Jan 1980 05:00:00 GMT&quot;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T09:14:34.700Z
Answers.LastActivityDate: 2021-02-03T09:14:34.700Z
Answers.UserDisplayName: Joorren
Body: <p>I'm having a problem with navigation that seems to get cached.</p>
  <p>If the page is loaded by someone who is not logged in, it shows the login button in the navigation (and it should).</p>
  <p>Once the user is logged in and returns to that specific page (by clicking a link on the site), the page still shows the login button.</p>
  <p>Only when the user manually refreshes the page, the login button gets replaced by the users name.</p>
  <hr />
  <p>The template code uses the currentUser variable, which is never overwritten anywhere else.
  There's no cache blocks used on the website, and the cache-control header is set to <code>no-store, no-cache, must-revalidate</code></p>
  <pre><code>{% if currentUser %}
      {% if currentUser.firstName != '' and currentUser.lastName != '' %}
          {{ currentUser.firstName }} {{ currentUser.lastName }}
      {% else %}
          {{ currentUser.email }}
      {% endif %}
  {% else %}
      {{ loginPage.title }}
  {% endif %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-25T19:38:23.413Z
Comments.Text: Have you verified in DevTools of your Browser, that the page really get the no-cache header? To me this sounds like a browser caching issue. Also try set the Expiry time in your .htaccess (or other server config) to 0 for HTML like this (only works with mod_expires on Apache):
   
  ExpiresActive on
  ExpiresByType text/html                             "access plus 0 seconds"
Comments.UserDisplayName: Matthias Redl-Mann
Tags: <craft3><cache><login><variable><current-user>
Title: currentUser gets cached
ThreadText: # currentUser gets cached
  
  (Asked by: username_0 on 2021-01-25)
  
  I'm having a problem with navigation that seems to get cached.
  
  If the page is loaded by someone who is not logged in, it shows the login button in the navigation (and it should).
  
  Once the user is logged in and returns to that specific page (by clicking a link on the site), the page still shows the login button.
  
  Only when the user manually refreshes the page, the login button gets replaced by the users name.
  
  ---
  
  The template code uses the currentUser variable, which is never overwritten anywhere else.
  There's no cache blocks used on the website, and the cache-control header is set to `no-store, no-cache, must-revalidate`
  
  ```
  {% if currentUser %}
      {% if currentUser.firstName != '' and currentUser.lastName != '' %}
          {{ currentUser.firstName }} {{ currentUser.lastName }}
      {% else %}
          {{ currentUser.email }}
      {% endif %}
  {% else %}
      {{ loginPage.title }}
  {% endif %}
  
  ```
  
  **Tags:** craft3, cache, login, variable, current-user
  
  > **Comments:**
  > **username_1**: Have you verified in DevTools of your Browser, that the page really get the no-cache header? To me this sounds like a browser caching issue. Also try set the Expiry time in your .htaccess (or other server config) to 0 for HTML like this (only works with mod_expires on Apache):   ExpiresActive on ExpiresByType text/html                             "access plus 0 seconds"  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-02-03. Score: 0 | Accepted answer
  
  It turns out the cache-control headers weren't coming through at the end.
  
  I solved the problem by adding all the right headers.
  
  ```
  Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
  
  ```
  
  
  ---
  
  