<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>

CC BY-SA 4.0
2018-05-29T17:12:56.030Z
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.
jsun
CC BY-SA 4.0
2018-05-29T18:40:38.487Z
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.
Frank Harrison
<cache><plugin-freeform>
Caching matrix that contains Freeform field
# 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 @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.  

---

## 0 answers

