<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>

CC BY-SA 3.0
2015-10-08T12:43:13.237Z
If possible, please include some example code – it'll make it easier to understand what's happening and to help you out :)
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-10-10T15:56:33.513Z
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.
Brad Bell
<cache>
Caching of categories is not purged on adding new category
# 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 %}
    {{ category.title }}

    
    
        
        
            {% nav category in craft.categories.descendantOf(category) %}
                {{ category.title }}
            {% endnav %}
           
    


    
        {% nav category in craft.categories.descendantOf(category) %}
        
            
            
                
                    {{ category.title }} - Producten
                    {% if category.teaser %}
                    {{ category.teaser }}
                    {% endif %}

                    
                        {% set entries = craft.entries.section('products').relatedTo(category) %}
                        {% for entry in entries %}
                        
                            {{ entry.title }}

                            
                                {{ entry.body }}
                            
                        
                        {% endfor %}
                    
                

                
                
                    Veel gestelde vragen

                    
                    
                    {% set entries = craft.entries.section('faq').relatedTo(category) %}
                    {% for entry in entries %}
                    
                        
                            
                                
                                    
                                    {{ entry.title }}
                                    
                                
                            

                            
                                
                                    {{ entry.answer }}  
                                
                            
                        
                    {% endfor %}
                    
                
              
          
    {% endnav %}
    



Graag vraag ik een offerte aan
{% 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

