<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>

CC BY-SA 3.0
2016-12-11T11:00:01.450Z
2016-12-11T11:00:01.450Z
KSPR
<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>

CC BY-SA 3.0
2016-11-30T12:06:34.910Z
Is it possible that you wanted to write "until" instead of "unless" in the template code?
Andris Sevcenko
CC BY-SA 3.0
2016-11-30T20:48:46.157Z
If you output `{{ newsDate }}`, `{{ eventDate }}` and `{{ currentTime }}`, are they what you expect?  Maybe a timezone difference?
Brad Bell
<templating><cache><expiration>
Invalidate cache from two channel expiry dates
# 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 %}


---

