Skip to main content
edited body
Source Link
Ben Parizek
  • 13.5k
  • 1
  • 35
  • 98

I'm currently working on integration some caching behaviour using {% cache %} tags. This works mostly just fine, but I have some issues when I work with related entries.

For example I have a list of categories with an indicator to show many entries they are assigned to.

  • New (3)
  • Used (2)
  • Broken (3)

If I change an entry and add a category, the cache refreshes and shows the correct amount. But if I remove a category from an entry I get the wrong number until I refresh the cache manually.

Is this the expected behaviour? Or do I miss something here?

Here is my code exmapleexample:

{% cache unless not craft.config.cache %}
{% set categorySlug = productSection ~ 'Categories' %}

<ul>

{% for category in craft.categories.group(categorySlug) %}
  {% set entryCount = craft.entries.relatedTo(category).total() %}
  {% if entryCount > 0 %}

    <li>
      {{ category.title }} ( {{ entryCount }} )
    </li>
    
  {% endif %}
{% endfor %}

</ul>

{% endcache %}

I'm currently working on integration some caching behaviour using {% cache %} tags. This works mostly just fine, but I have some issues when I work with related entries.

For example I have a list of categories with an indicator to show many entries they are assigned to.

  • New (3)
  • Used (2)
  • Broken (3)

If I change an entry and add a category, the cache refreshes and shows the correct amount. But if I remove a category from an entry I get the wrong number until I refresh the cache manually.

Is this the expected behaviour? Or do I miss something here?

Here is my code exmaple:

{% cache unless not craft.config.cache %}
{% set categorySlug = productSection ~ 'Categories' %}

<ul>

{% for category in craft.categories.group(categorySlug) %}
  {% set entryCount = craft.entries.relatedTo(category).total() %}
  {% if entryCount > 0 %}

    <li>
      {{ category.title }} ( {{ entryCount }} )
    </li>
    
  {% endif %}
{% endfor %}

</ul>

{% endcache %}

I'm currently working on integration some caching behaviour using {% cache %} tags. This works mostly just fine, but I have some issues when I work with related entries.

For example I have a list of categories with an indicator to show many entries they are assigned to.

  • New (3)
  • Used (2)
  • Broken (3)

If I change an entry and add a category, the cache refreshes and shows the correct amount. But if I remove a category from an entry I get the wrong number until I refresh the cache manually.

Is this the expected behaviour? Or do I miss something here?

Here is my code example:

{% cache unless not craft.config.cache %}
{% set categorySlug = productSection ~ 'Categories' %}

<ul>

{% for category in craft.categories.group(categorySlug) %}
  {% set entryCount = craft.entries.relatedTo(category).total() %}
  {% if entryCount > 0 %}

    <li>
      {{ category.title }} ( {{ entryCount }} )
    </li>
    
  {% endif %}
{% endfor %}

</ul>

{% endcache %}
Source Link

Caching and related Entries

I'm currently working on integration some caching behaviour using {% cache %} tags. This works mostly just fine, but I have some issues when I work with related entries.

For example I have a list of categories with an indicator to show many entries they are assigned to.

  • New (3)
  • Used (2)
  • Broken (3)

If I change an entry and add a category, the cache refreshes and shows the correct amount. But if I remove a category from an entry I get the wrong number until I refresh the cache manually.

Is this the expected behaviour? Or do I miss something here?

Here is my code exmaple:

{% cache unless not craft.config.cache %}
{% set categorySlug = productSection ~ 'Categories' %}

<ul>

{% for category in craft.categories.group(categorySlug) %}
  {% set entryCount = craft.entries.relatedTo(category).total() %}
  {% if entryCount > 0 %}

    <li>
      {{ category.title }} ( {{ entryCount }} )
    </li>
    
  {% endif %}
{% endfor %}

</ul>

{% endcache %}