Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-03T17:58:00.260Z
Answers.Text: 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.
Answers.UserDisplayName: kekona
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-03T18:01:46.490Z
Answers.Text: In that case you might be running into a bug. Please send us a ticket from your dashboard, including your templates and DB backup.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-26T19:50:31.873Z
Answers.Text: @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.
Answers.UserDisplayName: a-am
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-13T13:41:58.840Z
Answers.Text: @aran Sorry for the late reply. If you're still experiencing an issue, please contact support@buildwithcraft.com.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-21T21:36:38.250Z
Answers.Text: 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?
Answers.UserDisplayName: Marcus Scheller
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-03T13:42:45.237Z
Answers.LastActivityDate: 2014-07-03T13:42:45.237Z
Answers.UserDisplayName: Brandon Kelly
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-03T01:23:29.577Z
Comments.Text: I've had the same issue as well, basically had to turn off all caching for now until I find a fix
Comments.UserDisplayName: Keith Mancuso
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-03T07:20:57.613Z
Comments.Text: is the cache tag that wraps this line in the same template?
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-03T07:57:03.853Z
Comments.Text: Can you post the portion of the template that is using the cache tag?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-03T17:42:42.360Z
Comments.Text: I posted the full code block above with an additional note about observations deleting entries.
Comments.UserDisplayName: kekona
Tags: <templating><cache>
Title: Cached template content not invalidating
ThreadText: # 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) %}
      <div class="cardRow_column-carousel">
          <a href="{{ entry.url }}" class="card" >
              <div class="card_imageHolder">
                  <img class="card_image" src="{{ entry.tileImage.first().getUrl(cardCrop) }}">
              </div>
              <div class="card_content">
                  <h4 class="card_content_heading">{{ entry.title }}</h4>
                  <div class="card_content_icon">
                      {% 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 %}
                      <i class="{{ iconType }} card_content_icon-category"></i>
                      <i class="icon-arrow-right card_content_icon_arrow"></i>
                  </div>
              </div>
          </a>
      </div>
  {% 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:
  
  1. 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 %}
  
     ```
  2. 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**: @username_4 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?  
  
  ---
  
  