<p>It doesn't really matter where you have the tags. Yes, you do save the overhead of the include by wrapping the tag, but the impact is minimal (not really measurable) and once compiled to PHP it's cached anyways.</p>

<p>I usually have the cache tags <em>within</em> my partials. It's more flexible, you can cache blocks of code separately and leave out certain parts. I also often use the <code>globally</code> flag and include a partial into multiple templates. Defining the cache tag within the partial makes sure I always use the right cache ID.</p>

CC BY-SA 3.0
2016-04-19T22:50:58.687Z
2016-04-19T22:56:51.383Z
2016-04-19T22:56:51.383Z
carlcs
<p>When {% cache %} in conjunction with {% include ... %} is it better to wrap the Cache outside of the include or put inside of the included file?</p>

<pre><code>{% cache %}
    {% include %}
{% endcache %}

or

{% include "..." %} 

with the cache directives inside the include file?
</code></pre>

<p>Assume for this question that the entire contents of the include file will be cached (complex nav).</p>

<templating><cache>
Cache Order and Priority
# Cache Order and Priority

(Asked by: username_0 on 2016-04-19)

When {% cache %} in conjunction with {% include ... %} is it better to wrap the Cache outside of the include or put inside of the included file?
{% cache %}
    {% include %}
{% endcache %}

or

{% include "..." %} 

with the cache directives inside the include file?

Assume for this question that the entire contents of the include file will be cached (complex nav).

**Tags:** templating, cache


---

## 1 answers

### Answer by username_1 on 2016-04-19. Score: 2 | Accepted answer

It doesn't really matter where you have the tags. Yes, you do save the overhead of the include by wrapping the tag, but the impact is minimal (not really measurable) and once compiled to PHP it's cached anyways.

I usually have the cache tags *within* my partials. It's more flexible, you can cache blocks of code separately and leave out certain parts. I also often use the `globally` flag and include a partial into multiple templates. Defining the cache tag within the partial makes sure I always use the right cache ID.


---

