Body: <p>In a site we are currently developing I have setup a basic cache mechanism on each template that can benefit from it by reducing the number of db queries. 
  The {% cache %} tag is basically in the block on the different templates. It works great (helps to speed up load-times), but the cache is not purged when adding a new category to a category-group.</p>
  
  <p>The impacted template grasps all sort of information from different channels based on the selected main category and displays it ordered by subcategory. On adding a subcategory it gets not displayed unless the cache is being manually refreshed.  The odd thing is that when adding another subcategory (immediately after the cache refresh) the problem does not occur, but it only seems to happen after the cache has a certain age... </p>
  
  <pre><code>{% extends "_layouts/master" %}
  {% set title = category.title ~  " - Onderneming" %}
  {% set selected_menu_item = "business" %}
  {% set selected_submenu_item = category.id %}
  {% block body %}
  {% cache %}
      &lt;h2 class="extra-bottom-20"&gt;{{ category.title }}&lt;/h2&gt;
  
      &lt;!-- Start Tabbladen --&gt;
      &lt;div role="tabpanel"&gt;
          &lt;!-- Nav tabs --&gt;
          &lt;ul class="nav nav-tabs" role="tablist" id="myTab"&gt;
              {% nav category in craft.categories.descendantOf(category) %}
                  &lt;li role="presentation" {% if loop.first %} class="active" {% endif %}&gt;&lt;a href="#cat-{{category.id}}" aria-controls="cat-{{category.id}}" data-toggle="tab"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
              {% endnav %}
          &lt;/ul&gt;   
      &lt;/div&gt;
  
  
      &lt;div class="tab-content"&gt;
          {% nav category in craft.categories.descendantOf(category) %}
          &lt;div class="tab-pane {% if loop.first %} active {% endif %}" id="cat-{{category.id}}"&gt;
              &lt;!-- Start Producten --&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-lg-6"&gt;
                      &lt;h3 class="extra-bottom-20"&gt;{{ category.title }} - Producten&lt;/h3&gt;
                      {% if category.teaser %}
                      &lt;h4 class="alert alert-info"&gt;{{ category.teaser }}&lt;/h4&gt;
                      {% endif %}
  
                      &lt;ul class="sterlijst"&gt;
                          {% set entries = craft.entries.section('products').relatedTo(category) %}
                          {% for entry in entries %}
                          &lt;li&gt;
                              &lt;h5&gt;&lt;a href="#title-{{category.id}}-{{ entry.id }}" data-toggle="collapse" data-target="#title-{{category.id}}-{{ entry.id }}" data-parent="#{{category.id}}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h5&gt;
  
                              &lt;div id="title-{{category.id}}-{{ entry.id }}" class="collapse"&gt;
                                  {{ entry.body }}
                              &lt;/div&gt;
                          &lt;/li&gt;
                          {% endfor %}
                      &lt;/ul&gt;
                  &lt;/div&gt;&lt;!-- close col-lg-6 --&gt;
  
                  &lt;!-- start veelgestelde vragen --&gt;
                  &lt;div class="col-lg-6"&gt;
                      &lt;h3 class=""&gt;Veel gestelde vragen&lt;/h3&gt;
  
                      &lt;!-- start openklappen accordion --&gt;
                      &lt;div class="panel-group" id="accordion"&gt;
                      {% set entries = craft.entries.section('faq').relatedTo(category) %}
                      {% for entry in entries %}
                      &lt;!-- FAQs --&gt;
                          &lt;div class="panel panel-default"&gt;
                              &lt;div class="panel-heading"&gt;
                                  &lt;h4 class="panel-title"&gt;
                                      &lt;a data-toggle="collapse" data-parent="#accordion" href="#collapse-{{category.id}}-{{ entry.id }}"&gt;
                                      {{ entry.title }}
                                      &lt;/a&gt;
                                  &lt;/h4&gt;
                              &lt;/div&gt;
  
                              &lt;div id="collapse-{{category.id}}-{{ entry.id }}" class="panel-collapse collapse"&gt;
                                  &lt;div class="panel-body"&gt;
                                      {{ entry.answer }}  
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      {% endfor %}
                      &lt;/div&gt;&lt;!-- close panelgroup--&gt;
                  &lt;/div&gt;&lt;!-- close col-lg-6--&gt;
              &lt;/div&gt;  &lt;!-- close row--&gt;
          &lt;/div&gt;&lt;!-- /tabpanel 1 --&gt;  
      {% endnav %}
      &lt;/div&gt;
  
  
  &lt;hr width="50%" /&gt;
  &lt;p class="text-center"&gt;&lt;a href="{{siteUrl}}contact" class="btn btn-large btn-primary"&gt;Graag vraag ik een offerte aan&lt;/a&gt;&lt;/p&gt;
  {% endcache %}
  {% endblock %}
  </code></pre>
  
  <p>Maybe I should add that it only gives a problem with new categories, when adding new entries and assigning them to a subcategory they are displayed fine (cache is renewed)</p>
  
  <p>Any known issues with this or am I missing something? </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-08T12:43:13.237Z
Comments.Text: If possible, please include some example code – it'll make it easier to understand what's happening and to help you out :)
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-10T15:56:33.513Z
Comments.Text: So it only happens when adding new categories and even then only after a certain amount of time has passed? Are you sure you're not just running into stuck tasks? http://buildwithcraft.com/help/stuck-tasks Maybe try simplifying your template to get it down to a bare-bones reproducible test case.
Comments.UserDisplayName: Brad Bell
Tags: <cache>
Title: Caching of categories is not purged on adding new category
ThreadText: # Caching of categories is not purged on adding new category
  
  (Asked by: username_0 on 2015-10-08)
  
  In a site we are currently developing I have setup a basic cache mechanism on each template that can benefit from it by reducing the number of db queries.
  The {% cache %} tag is basically in the block on the different templates. It works great (helps to speed up load-times), but the cache is not purged when adding a new category to a category-group.
  
  The impacted template grasps all sort of information from different channels based on the selected main category and displays it ordered by subcategory. On adding a subcategory it gets not displayed unless the cache is being manually refreshed. The odd thing is that when adding another subcategory (immediately after the cache refresh) the problem does not occur, but it only seems to happen after the cache has a certain age...
  
  ```
  {% extends "_layouts/master" %}
  {% set title = category.title ~  " - Onderneming" %}
  {% set selected_menu_item = "business" %}
  {% set selected_submenu_item = category.id %}
  {% block body %}
  {% cache %}
      <h2 class="extra-bottom-20">{{ category.title }}</h2>
  
      <!-- Start Tabbladen -->
      <div role="tabpanel">
          <!-- Nav tabs -->
          <ul class="nav nav-tabs" role="tablist" id="myTab">
              {% nav category in craft.categories.descendantOf(category) %}
                  <li role="presentation" {% if loop.first %} class="active" {% endif %}><a href="#cat-{{category.id}}" aria-controls="cat-{{category.id}}" data-toggle="tab">{{ category.title }}</a></li>
              {% endnav %}
          </ul>   
      </div>
  
      <div class="tab-content">
          {% nav category in craft.categories.descendantOf(category) %}
          <div class="tab-pane {% if loop.first %} active {% endif %}" id="cat-{{category.id}}">
              <!-- Start Producten -->
              <div class="row">
                  <div class="col-lg-6">
                      <h3 class="extra-bottom-20">{{ category.title }} - Producten</h3>
                      {% if category.teaser %}
                      <h4 class="alert alert-info">{{ category.teaser }}</h4>
                      {% endif %}
  
                      <ul class="sterlijst">
                          {% set entries = craft.entries.section('products').relatedTo(category) %}
                          {% for entry in entries %}
                          <li>
                              <h5><a href="#title-{{category.id}}-{{ entry.id }}" data-toggle="collapse" data-target="#title-{{category.id}}-{{ entry.id }}" data-parent="#{{category.id}}">{{ entry.title }}</a></h5>
  
                              <div id="title-{{category.id}}-{{ entry.id }}" class="collapse">
                                  {{ entry.body }}
                              </div>
                          </li>
                          {% endfor %}
                      </ul>
                  </div><!-- close col-lg-6 -->
  
                  <!-- start veelgestelde vragen -->
                  <div class="col-lg-6">
                      <h3 class="">Veel gestelde vragen</h3>
  
                      <!-- start openklappen accordion -->
                      <div class="panel-group" id="accordion">
                      {% set entries = craft.entries.section('faq').relatedTo(category) %}
                      {% for entry in entries %}
                      <!-- FAQs -->
                          <div class="panel panel-default">
                              <div class="panel-heading">
                                  <h4 class="panel-title">
                                      <a data-toggle="collapse" data-parent="#accordion" href="#collapse-{{category.id}}-{{ entry.id }}">
                                      {{ entry.title }}
                                      </a>
                                  </h4>
                              </div>
  
                              <div id="collapse-{{category.id}}-{{ entry.id }}" class="panel-collapse collapse">
                                  <div class="panel-body">
                                      {{ entry.answer }}  
                                  </div>
                              </div>
                          </div>
                      {% endfor %}
                      </div><!-- close panelgroup-->
                  </div><!-- close col-lg-6-->
              </div>  <!-- close row-->
          </div><!-- /tabpanel 1 -->  
      {% endnav %}
      </div>
  
  <hr width="50%" />
  <p class="text-center"><a href="{{siteUrl}}contact" class="btn btn-large btn-primary">Graag vraag ik een offerte aan</a></p>
  {% endcache %}
  {% endblock %}
  
  ```
  
  Maybe I should add that it only gives a problem with new categories, when adding new entries and assigning them to a subcategory they are displayed fine (cache is renewed)
  
  Any known issues with this or am I missing something?
  
  **Tags:** cache
  
  > **Comments:**
  > **username_1**: If possible, please include some example code – it'll make it easier to understand what's happening and to help you out :)  
  > **username_2**: So it only happens when adding new categories and even then only after a certain amount of time has passed? Are you sure you're not just running into stuck tasks? http://buildwithcraft.com/help/stuck-tasks Maybe try simplifying your template to get it down to a bare-bones reproducible test case.  
  
  ---
  
  ## 0 answers
  
  