<p>When <strong>new</strong> elements are created, there’s no way for Craft to immediately know which template caches should be cleared. That’s where the <em>Delete Stale Template Caches</em> task comes in. It loops through all of your caches that included element queries, re-runs the queries, and checks to see if the new element is now included in the results.</p>

<p>There are two things to be aware of, though:</p>

<ol>
<li><p>Your element query must happen <em>inside</em> the <code>{% cache %}</code> tag pair.</p>

<pre><code>bad:

{% set entries = craft.entries.section('news').limit(3) %}
{% cache %}
    {% for entry in entries %}
        ...
    {% endfor %}
{% endcache %}

good:

{% cache %}
    {% set entries = craft.entries.section('news').limit(3) %}
    {% for entry in entries %}
        ...
    {% endfor %}
{% endcache %}
</code></pre></li>
<li><p>The cache querying is not immediate. After saving the entry you will see a little progress bar in the CP header. You need to wait until that has completed before your caches will be cleared.</p></li>
</ol>

CC BY-SA 3.0
2014-07-03T17:58:00.260Z
I edited my question and posted the code block which is wrapped in the cache tags.  I see the progress bar in the header when I save the entry. It completes pretty quickly and the entry still doesn't show up on the front-end, even if I wait for minutes. If I add an expiration time to the cache tag then I will see it show up.
kekona
CC BY-SA 3.0
2014-07-03T18:01:46.490Z
In that case you might be running into a bug. Please send us a ticket from your dashboard, including your templates and DB backup.
Brandon Kelly
CC BY-SA 3.0
2015-03-26T19:50:31.873Z
@BrandonKelly We are experiencing this same issue currently on a site.  Was this confirmed to be a bug? We are running Craft Pro 2.3.2640.
a-am
CC BY-SA 3.0
2015-04-13T13:41:58.840Z
@aran Sorry for the late reply. If you're still experiencing an issue, please contact support@buildwithcraft.com.
Brandon Kelly
CC BY-SA 3.0
2016-08-21T21:36:38.250Z
Sorry for digging this up. I am having a similar situation where the new entry gets created from a front end form. So the _Delete Stale Template Caches_ task won’t get fired (I assume). I can trigger it by moving to the cp and hit reload or navigate around. 

Is there a way to trigger that task from the front end on entry creation?
Marcus Scheller
CC BY-SA 3.0
2014-07-03T13:42:45.237Z
2014-07-03T13:42:45.237Z
Brandon Kelly
<p>My understanding of the {% cache %} tag is that if the content between it changes, the cache is invalidated and you see the new content.</p>

<p>I'm having an issue where a new entry is created in section, but it doesn't show up on the front-end unless I manually clear the cache in the control panel.</p>

<p>The content is pulled in via a loop such as:</p>

<pre><code>{%  for entry in craft.entries.section( "news" ).limit(3) %}
</code></pre>

<p>Am I not understanding how this tag works or is something going wrong?</p>

<p>Edit: Here is the full code block wrapped by cache tags</p>

<pre><code>{% cache %}
{%  for entry in craft.entries.section( item.nameId ).limit(3) %}
    &lt;div class="cardRow_column-carousel"&gt;
        &lt;a href="{{ entry.url }}" class="card" &gt;
            &lt;div class="card_imageHolder"&gt;
                &lt;img class="card_image" src="{{ entry.tileImage.first().getUrl(cardCrop) }}"&gt;
            &lt;/div&gt;
            &lt;div class="card_content"&gt;
                &lt;h4 class="card_content_heading"&gt;{{ entry.title }}&lt;/h4&gt;
                &lt;div class="card_content_icon"&gt;
                    {% if item.type == "video" %}
                        {% set iconType = "icon-video" %}
                    {% elseif item.type == "game" %}
                        {% set iconType = "icon-games" %}
                    {% elseif item.type == "image" or item.type == "imageGallery" %}
                        {% set iconType = "icon-image" %}
                    {% else %}
                        {% set iconType = "icon-paper" %}
                    {% endif %}
                    &lt;i class="{{ iconType }} card_content_icon-category"&gt;&lt;/i&gt;
                    &lt;i class="icon-arrow-right card_content_icon_arrow"&gt;&lt;/i&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/a&gt;
    &lt;/div&gt;
{% endfor %}
{% endcache %}
</code></pre>

<p>The strange thing that I'm noticing is if I add an entry it never shows up, but if I delete one it does get cleared out. And deleting an entry then causes the new one to show up.</p>

<p>UPDATE: Craft support determined there was a bug and plans to fix it in the next version. Current version is Craft 2.1 build 2563.</p>

CC BY-SA 3.0
2014-07-03T01:23:29.577Z
I've had the same issue as well, basically had to turn off all caching for now until I find a fix
Keith Mancuso
CC BY-SA 3.0
2014-07-03T07:20:57.613Z
is the cache tag that wraps this line in the same template?
Luke Holder
CC BY-SA 3.0
2014-07-03T07:57:03.853Z
Can you post the portion of the template that is using the cache tag?
Brad Bell
CC BY-SA 3.0
2014-07-03T17:42:42.360Z
I posted the full code block above with an additional note about observations deleting entries.
kekona
<templating><cache>
Cached template content not invalidating
# Cached template content not invalidating

(Asked by: username_0 on 2014-07-03)

My understanding of the {% cache %} tag is that if the content between it changes, the cache is invalidated and you see the new content.
I'm having an issue where a new entry is created in section, but it doesn't show up on the front-end unless I manually clear the cache in the control panel.
The content is pulled in via a loop such as:
{%  for entry in craft.entries.section( "news" ).limit(3) %}

Am I not understanding how this tag works or is something going wrong?
Edit: Here is the full code block wrapped by cache tags
{% cache %}
{%  for entry in craft.entries.section( item.nameId ).limit(3) %}
    
        
            
                
            
            
                {{ entry.title }}
                
                    {% if item.type == "video" %}
                        {% set iconType = "icon-video" %}
                    {% elseif item.type == "game" %}
                        {% set iconType = "icon-games" %}
                    {% elseif item.type == "image" or item.type == "imageGallery" %}
                        {% set iconType = "icon-image" %}
                    {% else %}
                        {% set iconType = "icon-paper" %}
                    {% endif %}
                    
                    
                
            
        
    
{% endfor %}
{% endcache %}

The strange thing that I'm noticing is if I add an entry it never shows up, but if I delete one it does get cleared out. And deleting an entry then causes the new one to show up.
UPDATE: Craft support determined there was a bug and plans to fix it in the next version. Current version is Craft 2.1 build 2563.

**Tags:** templating, cache

> **Comments:**
> **username_1**: I've had the same issue as well, basically had to turn off all caching for now until I find a fix  
> **username_2**: is the cache tag that wraps this line in the same template?  
> **username_3**: Can you post the portion of the template that is using the cache tag?  
> **username_0**: I posted the full code block above with an additional note about observations deleting entries.  

---

## 1 answers

### Answer by username_4 on 2014-07-03. Score: 4

When new elements are created, there’s no way for Craft to immediately know which template caches should be cleared. That’s where the Delete Stale Template Caches task comes in. It loops through all of your caches that included element queries, re-runs the queries, and checks to see if the new element is now included in the results.
There are two things to be aware of, though:

Your element query must happen inside the {% cache %} tag pair.
bad:

{% set entries = craft.entries.section('news').limit(3) %}
{% cache %}
    {% for entry in entries %}
        ...
    {% endfor %}
{% endcache %}

good:

{% cache %}
    {% set entries = craft.entries.section('news').limit(3) %}
    {% for entry in entries %}
        ...
    {% endfor %}
{% endcache %}

The cache querying is not immediate. After saving the entry you will see a little progress bar in the CP header. You need to wait until that has completed before your caches will be cleared.

> **Comments:**
> **username_0**: I edited my question and posted the code block which is wrapped in the cache tags.  I see the progress bar in the header when I save the entry. It completes pretty quickly and the entry still doesn't show up on the front-end, even if I wait for minutes. If I add an expiration time to the cache tag then I will see it show up.  
> **username_4**: In that case you might be running into a bug. Please send us a ticket from your dashboard, including your templates and DB backup.  
> **username_5**: @BrandonKelly We are experiencing this same issue currently on a site.  Was this confirmed to be a bug? We are running Craft Pro 2.3.2640.  
> **username_4**: @aran Sorry for the late reply. If you're still experiencing an issue, please contact support@buildwithcraft.com.  
> **username_6**: Sorry for digging this up. I am having a similar situation where the new entry gets created from a front end form. So the _Delete Stale Template Caches_ task won’t get fired (I assume). I can trigger it by moving to the cp and hit reload or navigate around.   Is there a way to trigger that task from the front end on entry creation?  

---

