Answers.Body: <p>When you first load the template using the <code>{% cache %}</code> tags, the number of queries will likely be higher because it still has to retrieve the correct data from the database.</p>
  
  <p>Subsequent loads of that template should show a lower amount of queries because it's returning actual cached content at that point.</p>
  
  <p>The same thing will happen once the cache is busted from expiration on the next template load as well.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-02T22:10:05.297Z
Answers.LastActivityDate: 2018-11-02T22:10:05.297Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have a question about the {% cache %} tag with Craft 3. I am reading this article (<a href="https://nystudio107.com/blog/the-craft-cache-tag-in-depth" rel="nofollow noreferrer">https://nystudio107.com/blog/the-craft-cache-tag-in-depth</a>), and trying out implementing the tags; however, when I check the amount of db queries before and after adding the tags, the amount of queries goes up instead of down as suggested in the article. </p>
  
  <p>What would cause this to happen? This is the code I’m currently testing the cache tag on, there are 5000+ entires in the 'articles' section. Without the cache tag there are 19 database queries, with it there are 32 queries.</p>
  
  <pre><code>{% cache %}
      {% for entry in craft.entries.section('articles').all() %}
        {{ entry.title }}&lt;br&gt;
      {% endfor %}
  {% endcache %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-27T21:27:46.130Z
Comments.Text: When you're checking the database queries, I'm assuming that's on first load, when there is currently no data cached?  Do subsequent loads have a smaller number of queries?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-31T14:16:32.593Z
Comments.Text: Hi Brad, thanks for the reply, that was the issue! The next few loads had 17 queries.
Comments.UserDisplayName: Brianne Hostutler
Tags: <craft3><cache>
Title: Craft 3 - Cache tag increasing number of database queries
ThreadText: # Craft 3 - Cache tag increasing number of database queries
  
  (Asked by: username_0 on 2018-10-25)
  
  I have a question about the {% cache %} tag with Craft 3. I am reading this article (<https://nystudio107.com/blog/the-craft-cache-tag-in-depth>), and trying out implementing the tags; however, when I check the amount of db queries before and after adding the tags, the amount of queries goes up instead of down as suggested in the article.
  
  What would cause this to happen? This is the code I’m currently testing the cache tag on, there are 5000+ entires in the 'articles' section. Without the cache tag there are 19 database queries, with it there are 32 queries.
  
  ```
  {% cache %}
      {% for entry in craft.entries.section('articles').all() %}
        {{ entry.title }}<br>
      {% endfor %}
  {% endcache %}
  
  ```
  
  **Tags:** craft3, cache
  
  > **Comments:**
  > **username_1**: When you're checking the database queries, I'm assuming that's on first load, when there is currently no data cached?  Do subsequent loads have a smaller number of queries?  
  > **username_0**: Hi username_1, thanks for the reply, that was the issue! The next few loads had 17 queries.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-11-02. Score: 2 | Accepted answer
  
  When you first load the template using the `{% cache %}` tags, the number of queries will likely be higher because it still has to retrieve the correct data from the database.
  
  Subsequent loads of that template should show a lower amount of queries because it's returning actual cached content at that point.
  
  The same thing will happen once the cache is busted from expiration on the next template load as well.
  
  
  ---
  
  