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!

  • Are there {% cache %} tags anywhere in your code? E.g. in a base template or anything else wrapping the entry or form templates? Commented Mar 31, 2016 at 12:40
  • I feel silly, that was it! A higher level template this was extending had a cache tag. Thanks @MatsMikkelRummelhoff! Commented Mar 31, 2016 at 13:21
  • No worries, @JamesMartin. I'll add an answer too, for good measure. Commented Mar 31, 2016 at 13:22

1 Answer 1


The {% cache %} tag does not exclude dynamic data.

What it does, is to basically make note of any element criteria (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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.