Answers.Body: <p>The <a href="https://craftcms.com/docs/templating/cache" rel="nofollow"><code>{% cache %}</code></a> tag does <em>not</em> exclude dynamic data.</p>
  
  <p>What it does, is to basically make note of any <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow">element criteria</a> (i.e. any code relating to pulling entries, categories, assets, tags or users) contained in the Twig code inside the <code>{% cache %}{% endcache %}</code> pair.</p>
  
  <p>Then, whenever something triggers a change to the related element criteria (e.g. if an entry is edited, published or deleted), the cache will automatically be cleared.</p>
  
  <p>This is all related to elements, though – so any other dynamic data you may have in your template, such as session variables, will not trigger the same behaviour.</p>
  
  <p>If your entry or form templates doesn't have any <code>{% cache %}</code> tags, I'm guessing you do have some in a base template wrapping your entry and form templates? If so, you'll need to take a more granular approach to your caching, e.g. by caching components separately and avoid <code>{% cache %}</code> tag nesting. To that end, your <code>unless</code> statement should work nicely for escaping dynamic data caching, as long as the component you're caching isn't wrapped by a higher-level <code>{% cache %}</code> tag.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-31T13:23:03.770Z
Answers.LastActivityDate: 2016-03-31T13:23:03.770Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I understood CraftCMS caching should exclude dynamic values, however I have a page built as an Entity within CraftCMS admin which <code>{% include %}</code>'s a template with a form.  The templates dynamic form values are somehow being rendered with cached values.</p>
  
  <p>The included template form uses dynamic values from e.g. <code>{{ craft.session.getFlash(key, '') }}</code> which are getting cached by CraftCMS causing the form to render with someone else's session values.</p>
  
  <p>Neither the Entity nor template had <code>{% cache %}</code> flags, and I've tried various cache settings to try and prevent such as <code>{% cache unless craft.session.hasFlash('key') %}</code> within the form template, and before the <code>{% include %}</code> within the Entity page, however the template is still rendered with cached form values.</p>
  
  <p>This is CraftCMS 2.4 with no custom caching plugins, using a Redis cache store and default Craft caching config values.</p>
  
  <p>How can I prevent this? Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-31T12:40:27.530Z
Comments.Text: Are there `{% cache %}` tags anywhere in your code? E.g. in a base template or anything else wrapping the entry or form templates?
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-31T13:21:31.270Z
Comments.Text: I feel silly, that was it!  A higher level template this was extending had a cache tag.  Thanks @MatsMikkelRummelhoff!
Comments.UserDisplayName: James Martin
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-31T13:22:09.067Z
Comments.Text: No worries, @JamesMartin. I'll add an answer too, for good measure.
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Tags: <cache>
Title: Prevent craftcms caching CMS page with dynamic template
ThreadText: # Prevent craftcms caching CMS page with dynamic template
  
  (Asked by: username_0 on 2016-03-31)
  
  I understood CraftCMS caching should exclude dynamic values, however I have a page built as an Entity within CraftCMS admin which `{% include %}`'s a template with a form. The templates dynamic form values are somehow being rendered with cached values.
  
  The included template form uses dynamic values from e.g. `{{ craft.session.getFlash(key, '') }}` which are getting cached by CraftCMS causing the form to render with someone else's session values.
  
  Neither the Entity nor template had `{% cache %}` flags, and I've tried various cache settings to try and prevent such as `{% cache unless craft.session.hasFlash('key') %}` within the form template, and before the `{% include %}` within the Entity page, however the template is still rendered with cached form values.
  
  This is CraftCMS 2.4 with no custom caching plugins, using a Redis cache store and default Craft caching config values.
  
  How can I prevent this? Thanks!
  
  **Tags:** cache
  
  > **Comments:**
  > **username_1**: Are there `{% cache %}` tags anywhere in your code? E.g. in a base template or anything else wrapping the entry or form templates?  
  > **username_0**: I feel silly, that was it!  A higher level template this was extending had a cache tag.  Thanks @username_1!  
  > **username_1**: No worries, @username_0. I'll add an answer too, for good measure.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-31. Score: 4 | Accepted answer
  
  The [`{% cache %}`](https://craftcms.com/docs/templating/cache) tag does *not* exclude dynamic data.
  
  What it does, is to basically make note of any [element criteria](https://craftcms.com/docs/templating/elementcriteriamodel) (i.e. any code relating to pulling entries, categories, assets, tags or users) contained in the Twig code inside the `{% cache %}{% endcache %}` pair.
  
  Then, whenever something triggers a change to the related element criteria (e.g. if an entry is edited, published or deleted), the cache will automatically be cleared.
  
  This is all related to elements, though – so any other dynamic data you may have in your template, such as session variables, will not trigger the same behaviour.
  
  If your entry or form templates doesn't have any `{% cache %}` tags, I'm guessing you do have some in a base template wrapping your entry and form templates? If so, you'll need to take a more granular approach to your caching, e.g. by caching components separately and avoid `{% cache %}` tag nesting. To that end, your `unless` statement should work nicely for escaping dynamic data caching, as long as the component you're caching isn't wrapped by a higher-level `{% cache %}` tag.
  
  
  ---
  
  