<p>Yes, the database query you'd want to cache is this:</p>

<pre><code>{% paginate craft.entries.section('employment').endDate('&gt;= ' ~ now).limit(10) as pageInfo, pageEntries %}
</code></pre>

<p>So to get the benefits of caching, it needs to be within the cache tag.</p>

CC BY-SA 3.0
2017-08-08T09:14:34.347Z
Just to be clear and avoid confusion - Craft does not cache the query; the cache tags only cache the output HTML.
Matt Wilcox
CC BY-SA 3.0
2017-08-07T21:36:40.850Z
2017-08-07T21:36:40.850Z
André Elvan
<p>When using cache tag with pagination should the tag go outside the pagination tag?</p>

<pre><code>{% cache %}
&lt;div class="grid-x grid-padding-x" data-equalizer data-equalize-on="medium"&gt;
    {% paginate craft.entries.section('employment').endDate('&gt;= ' ~ now).limit(10) as pageInfo, pageEntries %}
    {% for entry in pageEntries %}
        &lt;div class="small-12 medium-6 large-6 cell"&gt;
            &lt;div class="news-card" data-equalizer-watch&gt;
                &lt;div class="card-section text-center"&gt;
                    &lt;h5&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h5&gt;
                    &lt;p&gt;
                    &lt;span class="label my-purple"&gt;
                        {% if entry.openUntilFilled %}
                            Open Until Filled
                        {% else %}
                            Job Closing: {{ entry.endDate.format('M j, Y') }}
                        {% endif %}
                    &lt;/span&gt;
                    &lt;/p&gt;
                    &lt;p&gt;{{ entry.body|length &gt; 1 ? entry.body|striptags|slice(0, 150) ~ '...' : entry.body }}&lt;/p&gt;
                    &lt;p&gt;&lt;a class="more" href="{{ entry.url }}"&gt;Read More&lt;/a&gt;&lt;/p&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    {% endfor %}
&lt;/div&gt;
&lt;div class="grid-x grid-padding-x"&gt;
    &lt;div class="small-12 cell"&gt;
        {% if pageInfo.prevUrl %}&lt;a href="{{ pageInfo.prevUrl }}"&gt;Previous Page&lt;/a&gt;&amp;nbsp;{% endif %}
        {% if pageInfo.nextUrl %}&lt;a href="{{ pageInfo.nextUrl }}"&gt;Next Page&lt;/a&gt;{% endif %}
    &lt;/div&gt;
&lt;/div&gt;
{% endcache %}
</code></pre>

<cache><pagination>
How to use `{% cache %}` and `{% paginate %}` together?
# How to use `{% cache %}` and `{% paginate %}` together?

(Asked by: username_0 on 2017-08-07)

When using cache tag with pagination should the tag go outside the pagination tag?
{% cache %}

    {% paginate craft.entries.section('employment').endDate('>= ' ~ now).limit(10) as pageInfo, pageEntries %}
    {% for entry in pageEntries %}
        
            
                
                    {{ entry.title }}
                    
                    
                        {% if entry.openUntilFilled %}
                            Open Until Filled
                        {% else %}
                            Job Closing: {{ entry.endDate.format('M j, Y') }}
                        {% endif %}
                    
                    
                    {{ entry.body|length > 1 ? entry.body|striptags|slice(0, 150) ~ '...' : entry.body }}
                    Read More
                
            
        
    {% endfor %}


    
        {% if pageInfo.prevUrl %}Previous Page {% endif %}
        {% if pageInfo.nextUrl %}Next Page{% endif %}
    

{% endcache %}

**Tags:** cache, pagination

---

## 1 answers

### Answer by username_1 on 2017-08-07. Score: 1

Yes, the database query you'd want to cache is this:
{% paginate craft.entries.section('employment').endDate('>= ' ~ now).limit(10) as pageInfo, pageEntries %}

So to get the benefits of caching, it needs to be within the cache tag.

> **Comments:**
> **username_2**: Just to be clear and avoid confusion - Craft does not cache the query; the cache tags only cache the output HTML.  

---

