Answers.Body: <p>the error was with the <code>date</code> format in the date comparison conditional and the <code>until</code> tag instead of <code>unless</code></p>
  
  <pre><code>{% if currentTime &lt;= newsDate | date('c') %} {# those two dates were formated differentely #}
      {% set invalidate = newsDate.expiryDate | date('c') %}
  {% else %}
      {% set invalidate = auffuehrung.konzertStartdate |date('c') %}
  {% endif %}
  
  {% cache until invalidate %} {# not unless #}
   {# blablabla #}
  {% endcache %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-11T11:00:01.450Z
Answers.LastActivityDate: 2016-12-11T11:00:01.450Z
Answers.UserDisplayName: KSPR
Body: <p>I have two channels: A event and a news channel which I want the cache to expire based on both their expiry Date.</p>
  
  <pre><code>{% set newsDate = craft.entries.section('newsDate').order('expiryDate asc').first() %}
  {% set eventDate = craft.entries.section('event').order('konzertStartdate asc').first() %}
  {% set currentTime = now |date('c') %}
  
  {% if currentTime &lt;= newsDate %}
      {% set invalidate = newsDate.expiryDate | date('c') %}
  {% else %}
      {% set invalidate = auffuehrung.konzertStartdate |date('c') %}
  {% endif %}
  
  {% cache unless invalidate %}
   {# blablabla #}
  {% endcache %}
  </code></pre>
  
  <p>As you can see I create two variables and then check which one is newer. But its not working properly.</p>
  
  <p>The news never seem to invalidate the cache.</p>
  
  <p>Do you know a better way to do this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-30T12:06:34.910Z
Comments.Text: Is it possible that you wanted to write "until" instead of "unless" in the template code?
Comments.UserDisplayName: Andris Sevcenko
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-30T20:48:46.157Z
Comments.Text: If you output `{{ newsDate }}`, `{{ eventDate }}` and `{{ currentTime }}`, are they what you expect?  Maybe a timezone difference?
Comments.UserDisplayName: Brad Bell
Tags: <templating><cache><expiration>
Title: Invalidate cache from two channel expiry dates
ThreadText: # Invalidate cache from two channel expiry dates
  
  (Asked by: username_0 on 2016-11-30)
  
  I have two channels: A event and a news channel which I want the cache to expire based on both their expiry Date.
  
  ```
  {% set newsDate = craft.entries.section('newsDate').order('expiryDate asc').first() %}
  {% set eventDate = craft.entries.section('event').order('konzertStartdate asc').first() %}
  {% set currentTime = now |date('c') %}
  
  {% if currentTime <= newsDate %}
      {% set invalidate = newsDate.expiryDate | date('c') %}
  {% else %}
      {% set invalidate = auffuehrung.konzertStartdate |date('c') %}
  {% endif %}
  
  {% cache unless invalidate %}
   {# blablabla #}
  {% endcache %}
  
  ```
  
  As you can see I create two variables and then check which one is newer. But its not working properly.
  
  The news never seem to invalidate the cache.
  
  Do you know a better way to do this?
  
  **Tags:** templating, cache, expiration
  
  > **Comments:**
  > **username_1**: Is it possible that you wanted to write "until" instead of "unless" in the template code?  
  > **username_2**: If you output `{{ newsDate }}`, `{{ eventDate }}` and `{{ currentTime }}`, are they what you expect?  Maybe a timezone difference?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-12-11. Score: 1 | Accepted answer
  
  the error was with the `date` format in the date comparison conditional and the `until` tag instead of `unless`
  
  ```
  {% if currentTime <= newsDate | date('c') %} {# those two dates were formated differentely #}
      {% set invalidate = newsDate.expiryDate | date('c') %}
  {% else %}
      {% set invalidate = auffuehrung.konzertStartdate |date('c') %}
  {% endif %}
  
  {% cache until invalidate %} {# not unless #}
   {# blablabla #}
  {% endcache %}
  
  ```
  
  
  ---
  
  