Body: <p>I've got a matrix block that most pages on my site are built from, and one of its blocks is a Solspace Freeform form field. I want to be able to cache the entire output of the matrix, but that makes Freeform see all form submissions as spam, since their hash gets cached too.</p>
  
  <p>So I tried <a href="https://github.com/benjamminf/craft-nocache" rel="nofollow noreferrer">https://github.com/benjamminf/craft-nocache</a> but couldn't get that to work as the whole matrix (including the form) gets cached outside of the <code>{% nocache %}</code> tag. So then I tried:</p>
  
  <pre><code>{% set bodyIncludesForm = entry.body.type('form') | length &gt; 0 %}
  {% cache globally using key craft.request.path unless bodyIncludesForm %}
  ...
  </code></pre>
  
  <p>... which seems to work, but that <code>entry.body.type('form')</code> call adds 32 queries which kind of defies the point of the caching!</p>
  
  <p>Any idea how to get round this, without turning off Freeform's spam check?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-29T17:12:56.030Z
Comments.Text: Not exactly sure what the FreeForm markup is like, but I've done something similar to the solution [here](https://craftcms.stackexchange.com/questions/13852/how-can-i-prevent-csrf-tokens-from-being-cached) for csrf tokens.
Comments.UserDisplayName: jsun
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-29T18:40:38.487Z
Comments.Text: Thanks @jsun. Freeform doesn't use csrf tokens – it outputs a hidden field called "formHash" which I guess might work the same way. But the only way to output that myself (to do a find and replace) would be to call `entry.body.type('form')` outside of the cache loop, and that seems really expensive, adding 32 queries.
Comments.UserDisplayName: Frank Harrison
Tags: <cache><plugin-freeform>
Title: Caching matrix that contains Freeform field
ThreadText: # Caching matrix that contains Freeform field
  
  (Asked by: username_0 on 2018-05-29)
  
  I've got a matrix block that most pages on my site are built from, and one of its blocks is a Solspace Freeform form field. I want to be able to cache the entire output of the matrix, but that makes Freeform see all form submissions as spam, since their hash gets cached too.
  
  So I tried <https://github.com/benjamminf/craft-nocache> but couldn't get that to work as the whole matrix (including the form) gets cached outside of the `{% nocache %}` tag. So then I tried:
  
  ```
  {% set bodyIncludesForm = entry.body.type('form') | length > 0 %}
  {% cache globally using key craft.request.path unless bodyIncludesForm %}
  ...
  
  ```
  
  ... which seems to work, but that `entry.body.type('form')` call adds 32 queries which kind of defies the point of the caching!
  
  Any idea how to get round this, without turning off Freeform's spam check?
  
  **Tags:** cache, plugin-freeform
  
  > **Comments:**
  > **username_1**: Not exactly sure what the FreeForm markup is like, but I've done something similar to the solution [here](https://craftcms.stackexchange.com/questions/13852/how-can-i-prevent-csrf-tokens-from-being-cached) for csrf tokens.  
  > **username_0**: Thanks @username_1. Freeform doesn't use csrf tokens – it outputs a hidden field called "formHash" which I guess might work the same way. But the only way to output that myself (to do a find and replace) would be to call `entry.body.type('form')` outside of the cache loop, and that seems really expensive, adding 32 queries.  
  
  ---
  
  ## 0 answers
  
  