Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-08T09:14:34.347Z
Answers.Text: Just to be clear and avoid confusion - Craft does not cache the query; the cache tags only cache the output HTML.
Answers.UserDisplayName: Matt Wilcox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-07T21:36:40.850Z
Answers.LastActivityDate: 2017-08-07T21:36:40.850Z
Answers.UserDisplayName: André Elvan
Body: <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>
  
Tags: <cache><pagination>
Title: How to use `{% cache %}` and `{% paginate %}` together?
ThreadText: # 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 %}
  <div class="grid-x grid-padding-x" data-equalizer data-equalize-on="medium">
      {% paginate craft.entries.section('employment').endDate('>= ' ~ now).limit(10) as pageInfo, pageEntries %}
      {% for entry in pageEntries %}
          <div class="small-12 medium-6 large-6 cell">
              <div class="news-card" data-equalizer-watch>
                  <div class="card-section text-center">
                      <h5><a href="{{ entry.url }}">{{ entry.title }}</a></h5>
                      <p>
                      <span class="label my-purple">
                          {% if entry.openUntilFilled %}
                              Open Until Filled
                          {% else %}
                              Job Closing: {{ entry.endDate.format('M j, Y') }}
                          {% endif %}
                      </span>
                      </p>
                      <p>{{ entry.body|length > 1 ? entry.body|striptags|slice(0, 150) ~ '...' : entry.body }}</p>
                      <p><a class="more" href="{{ entry.url }}">Read More</a></p>
                  </div>
              </div>
          </div>
      {% endfor %}
  </div>
  <div class="grid-x grid-padding-x">
      <div class="small-12 cell">
          {% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}">Previous Page</a>&nbsp;{% endif %}
          {% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl }}">Next Page</a>{% endif %}
      </div>
  </div>
  {% 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.  
  
  ---
  
  