Answers.Body: <p>Based on the code you posted on pastebin, it seems like the problem is that you have your pagination outside of the cache tags (assuming this was the case when you had caching implemented). And, I'm assuming that inside your <code>{% include "_includes/pagination" %}</code> you're trying to access <code>pageInfo</code>, which is created by the pagination tag. </p>
  
  <p>To make this work, and be able to implement efficient caching, you need to include your pagination inside your cache tags. In fact, I would also include the logic that creates the <code>topicEntries</code> element criteria above where you have the pagination tag today, inside the cache tag, as it creates DB queries and is directly related to the content you want to cache. </p>
  
  <p>The overall structure of your code should then be:</p>
  
  <pre><code>{% cache globally using key craft.request.path ~ '/p' ~ craft.request.getPageNum for 2 hours %}
      &lt;ul class="feat-box-container"&gt;
          {#  lots of code to get topicEntries #}
  
          {% paginate topicEntries.limit(10) as pageInfo, topicEntries %}
  
          {% for topic in topicEntries %}
              {# code that outputs list items #}
          {% endfor %}
      &lt;/ul&gt;
  
      {% include "_includes/pagination" %}
  {% endcache %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-11T13:46:45.037Z
Answers.Text: This appears to be working, however when I add a new entry to the section, the cache is not broken and new entries do not display.
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-10T19:20:16.497Z
Answers.LastActivityDate: 2018-04-10T19:20:16.497Z
Answers.UserDisplayName: André Elvan
Body: <p>I'm trying to get pagination and cache to work together but it's failing.</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>{% cache globally using key
     craft.request.path ~ '/p' ~ craft.request.getPageNum
     for 2 hours %}
  
  {% paginate topicEntries.limit(10)as pageInfo, topicEntries %}
  
    {% for topic in topicEntries %}
  
        more code here
  
    {% endfor %}
  
  {% endcache %
  </code></pre>
  
  <p>When I use this I get a template error that Variable pageInfo does not exist.</p>
  
  <p>Then if I put the opening cache tag below the paginate tag. The first page shows 10 entries, but each page after that only displays 1 entry per page.</p>
  
  <pre><code>{% paginate topicEntries.limit(10)as pageInfo, topicEntries %}
   {% cache globally using key
      craft.request.path ~ '/p' ~ craft.request.getPageNum
      for 2 hours %}
  
    {% for topic in topicEntries %}
  
        more code here
  
    {% endfor %}
  
  {% endcache %}
  </code></pre>
  
  <p>What I need to know is how to cache paginated entries so it's 10 per page and when a new entry is added the cache is cleared correctly.</p>
  
  <p>Please advise.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-10T13:31:24.203Z
Comments.Text: First of all, is your code actually `{% paginate topicEntries.limit(10)as pageInfo, topicEntries %}`? If so, you're missing a space between `limit(10)` and `as`. Guessing that's just an error here on SE, since that'd give you some other error. Also, I suspect that there are some code that accesses `pageInfo` that's outside of the code that's shown here? If `pageInfo` is created inside the cache tag, you can't access it outside. Seeing the rest of your template code would be useful.
Comments.UserDisplayName: André Elvan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-10T17:38:08.680Z
Comments.Text: @AndréElvan this template is an include - have posted the full include file here: https://pastebin.com/A0b8Pfv1
Comments.UserDisplayName: CreateSean
Tags: <templating><cache><pagination>
Title: Cache and Pagination not working
ThreadText: # Cache and Pagination not working
  
  (Asked by: username_0 on 2018-04-06)
  
  I'm trying to get pagination and cache to work together but it's failing.
  
  Here's my current code:
  
  ```
  {% cache globally using key
     craft.request.path ~ '/p' ~ craft.request.getPageNum
     for 2 hours %}
  
  {% paginate topicEntries.limit(10)as pageInfo, topicEntries %}
  
    {% for topic in topicEntries %}
  
        more code here
  
    {% endfor %}
  
  {% endcache %
  
  ```
  
  When I use this I get a template error that Variable pageInfo does not exist.
  
  Then if I put the opening cache tag below the paginate tag. The first page shows 10 entries, but each page after that only displays 1 entry per page.
  
  ```
  {% paginate topicEntries.limit(10)as pageInfo, topicEntries %}
   {% cache globally using key
      craft.request.path ~ '/p' ~ craft.request.getPageNum
      for 2 hours %}
  
    {% for topic in topicEntries %}
  
        more code here
  
    {% endfor %}
  
  {% endcache %}
  
  ```
  
  What I need to know is how to cache paginated entries so it's 10 per page and when a new entry is added the cache is cleared correctly.
  
  Please advise.
  
  **Tags:** templating, cache, pagination
  
  > **Comments:**
  > **username_1**: First of all, is your code actually `{% paginate topicEntries.limit(10)as pageInfo, topicEntries %}`? If so, you're missing a space between `limit(10)` and `as`. Guessing that's just an error here on SE, since that'd give you some other error. Also, I suspect that there are some code that accesses `pageInfo` that's outside of the code that's shown here? If `pageInfo` is created inside the cache tag, you can't access it outside. Seeing the rest of your template code would be useful.  
  > **username_0**: @username_1 this template is an include - have posted the full include file here: https://pastebin.com/A0b8Pfv1  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-10. Score: 3
  
  Based on the code you posted on pastebin, it seems like the problem is that you have your pagination outside of the cache tags (assuming this was the case when you had caching implemented). And, I'm assuming that inside your `{% include "_includes/pagination" %}` you're trying to access `pageInfo`, which is created by the pagination tag.
  
  To make this work, and be able to implement efficient caching, you need to include your pagination inside your cache tags. In fact, I would also include the logic that creates the `topicEntries` element criteria above where you have the pagination tag today, inside the cache tag, as it creates DB queries and is directly related to the content you want to cache.
  
  The overall structure of your code should then be:
  
  ```
  {% cache globally using key craft.request.path ~ '/p' ~ craft.request.getPageNum for 2 hours %}
      <ul class="feat-box-container">
          {#  lots of code to get topicEntries #}
  
          {% paginate topicEntries.limit(10) as pageInfo, topicEntries %}
  
          {% for topic in topicEntries %}
              {# code that outputs list items #}
          {% endfor %}
      </ul>
  
      {% include "_includes/pagination" %}
  {% endcache %}
  
  ```
  
  > **Comments:**
  > **username_0**: This appears to be working, however when I add a new entry to the section, the cache is not broken and new entries do not display.  
  
  ---
  
  