<p>General answer: It is not wrong to put <code>include</code> tags in <code>cache</code> tags.</p>

CC BY-SA 4.0
2019-10-16T11:29:09.010Z
2019-10-16T11:29:09.010Z
Matthias Redl-Mann
<p>I was wondering if it makes sense to wrap these {% cache %} around {% include %} tags that call a separate file with params. Is it better to just include them in the actual file itself?</p>

<p>For example, I was using cache tags around includes that call main navigation HTML in the header, like so:</p>

<pre><code>{% cache globally %}
  {% include '_partials/navigation/config.twig' with {
     menuLinks: menuNavLinks,
     direction: "right",
     type: "header" 
   }%}
{% endcache %}
</code></pre>

<p>This was causing an allocated memory error that took me forever to debug. FYI I am running locally on XAMPP and my memory_limit is set to 128M; when I increased this, it caused even more issues, related to Database Exception "MySQL error 2006: mysql server has gone away."</p>

<p>Is this not advised and against proper {% cache %} practices?</p>

<templating><craft3><cache><mysql><include>
Using {% cache %} tags around {% template %} includes (or in Header)
# Using {% cache %} tags around {% template %} includes (or in Header)

(Asked by: username_0 on 2019-10-15)

I was wondering if it makes sense to wrap these {% cache %} around {% include %} tags that call a separate file with params. Is it better to just include them in the actual file itself?
For example, I was using cache tags around includes that call main navigation HTML in the header, like so:
{% cache globally %}
  {% include '_partials/navigation/config.twig' with {
     menuLinks: menuNavLinks,
     direction: "right",
     type: "header" 
   }%}
{% endcache %}

This was causing an allocated memory error that took me forever to debug. FYI I am running locally on XAMPP and my memory_limit is set to 128M; when I increased this, it caused even more issues, related to Database Exception "MySQL error 2006: mysql server has gone away."
Is this not advised and against proper {% cache %} practices?

**Tags:** templating, craft3, cache, mysql, include


---

## 1 answers

### Answer by username_1 on 2019-10-16. Score: 1

General answer: It is not wrong to put `include` tags in `cache` tags.


---

