0

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?

  • 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 Oct 8 '15 at 12:43
  • 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? buildwithcraft.com/help/stuck-tasks Maybe try simplifying your template to get it down to a bare-bones reproducible test case. – Brad Bell Oct 10 '15 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.