<p>You could use the new <a href="https://github.com/pixelandtonic/ColdCache/" rel="nofollow">Cold Cache pluging from P&amp;T</a> which:</p>

<blockquote>
  <p>Adds a new <code>{% coldcache %}</code> tag to Craft, which works just like Craft’s
  built-in <code>{% cache %}</code> tag, except that this tag won’t record which
  elements and element queries are active between its tags. The only way
  caches will ever get deleted is if they expire, or an admin clears
  them using the Clear Caches tool in Settings.</p>
</blockquote>

CC BY-SA 3.0
2014-09-09T16:00:56.593Z
I know that coldcache exists, but that doesn't solve the problem, or does it?
outline4
CC BY-SA 3.0
2014-09-09T16:05:28.517Z
I don't know how your template looks, but I would create two for-loops: One for the current year (and wrap it in `{% cache until nextEvent %}`) and one for everything else (`{% coldcache %}`).
Victor
CC BY-SA 3.0
2014-09-09T16:08:55.897Z
just after posting my remark, I understood what you meant... I've updated the question as well. Two loops would be an option - you are completely right... I wish there was a way with only one loop, but I guess it's OK like you proposed... btw: don't really need coldcache, I just don't want to break it every night... cheers
outline4
CC BY-SA 3.0
2014-09-10T11:05:22.103Z
@outline4 Now I understand that you have a separate page for each year. Why don't you just use `{% cache %}`? It will be saved for each page separately and only cleared when an entry matching that query gets updated.
Victor
CC BY-SA 3.0
2014-09-10T13:36:16.457Z
no, since it's event based, the events are only going into the archive after a certain date, not when they are edited! that's what it's all about... I will update the question with the answer. that I actually found because of your initial comment ;)
outline4
CC BY-SA 3.0
2014-09-10T13:43:26.287Z
@outline4 Glad you got it sorted ;)
Victor
CC BY-SA 3.0
2014-09-09T11:54:45.267Z
2014-09-09T11:54:45.267Z
Victor
<p>I have an archive of an event based site. 
I know how to break cache until the next event. No Problem</p>

<pre><code>{% cache until nextEvent %}
</code></pre>

<p>But the archive works the following way: </p>

<p>archive<br>
-- 2014 (latest year)<br>
-- 2013<br>
-- 2012<br>
-- 2011  </p>

<p>The until nextEvent part makes only sense for the latest year. The other years should be cached forever. </p>

<p>How could I achieve such a thing? </p>

<p>-- edit --</p>

<p>Maybe I have to go a little more into the details:<br>
I get the year in the forth segment.<br>
Now it should cache the whole loop and never break it, unless it's the actual year, then break it each night: </p>

<pre><code>{% set latestYear = now|date("Y") %}

{% if year is not defined %}
    {% redirect "club/programm/archiv/"~latestYear %}
{% endif %}

{% set year = craft.request.getSegment(4) %}

{# Set the first day of the year and the last #}
{% set lastyear = year -1 %}
{% set nextyear = year +1 %}
{% set yearbegins = '1 January ' ~ year %}
{% set yearends = '1 January ' ~ nextyear %}
{% set unixbegins = yearbegins | date('U') %}
{% set unixends = yearends | date('U') %}

{# Today at 00:00 #}
{% set today = now|date("Y-m-d") ~ ' 00:00' %}
{% set tomorrow = now|date_modify("+1 day")|date("Y-m-d") ~ ' 00:00' %}

{% set entriesByYear = craft.entries.section('programm').limit(null).cf_date('and', '&gt;= ' ~ unixbegins, '&lt; ' ~ unixends, '&lt; ' ~ today| date("U")) %} {# '&gt; just to make syntax highlighting correct #}

{% cache until tomorrow %}
    {% for month, entries in entriesByYear | group("postDate|date('F')") %}

        {# MONTHLY HEADER #}
        &lt;div class="program_monthly_header"&gt;
            &lt;div class="content_column"&gt;
                &lt;p&gt;{{ month }} {{ year }} &lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        {# ENTRIES PER MONTH #}
        {% for entry in entries %}

            &lt;div class="listing_item{% if loop.last %} last{% endif %}" id="programm_{{ entry.slug }}"&gt; 
                {% include "programm/_common" %}                    
            &lt;/div&gt;
            &lt;div class="clear"&gt;&lt;/div&gt;
        {% endfor %}
    {% endfor %}
{% endcache %}
</code></pre>

<p>maybe that helps someone to help me ;)<br>
cheers<br>
stefan</p>

<p>--- edit 2 and solution --- </p>

<p>so after the comments of victor I updated the code. and it works like a charm: </p>

<pre><code>{% set latestYear = now|date("Y") %}

{% if year is not defined %}
    {% redirect "club/programm/archiv/"~latestYear %}
{% endif %}

{% set year = craft.request.getSegment(4) %}

{# Set the first day of the year and the last #}
{% set lastyear = year -1 %}
{% set nextyear = year +1 %}
{% set yearbegins = '1 January ' ~ year %}
{% set yearends = '1 January ' ~ nextyear %}
{% set unixbegins = yearbegins | date('U') %}
{% set unixends = yearends | date('U') %}

{# Today at 00:00 #}
{% set today = now|date("Y-m-d") ~ ' 00:00' %}
{% set tomorrow = now|date_modify("+1 day")|date("Y-m-d") ~ ' 00:00' %}

{# Get the Date of the next Event, to allow caching until then #}
{% set nextEvent = craft.entries.section('programm').cf_date('&gt;= ' ~ today| date("U")).order('cf_date asc').first() %}{# '&gt; just to make syntax highlighting correct #}
{% set nextEventDate = nextEvent.cf_date|date_modify("+1 day")|date("Y-m-d") ~ ' 00:00' %}

{# Get all the events within the year concerned #}  
{% set entriesByYear = craft.entries.section('programm').limit(null).cf_date('and', '&gt;= ' ~ unixbegins, '&lt; ' ~ unixends, '&lt; ' ~ today| date("U")) %} {# '&gt; just to make syntax highlighting correct #}

{# If the year is the current year, cache it until the next event. Otherwhise, cache indefinitely #}
{% if year == latestYear %}
    {% cache until nextEventDate %}
        {% include "club/programm/_archive_common" %}
    {% endcache %}
{% else %}
    {% cache %}
        {% include "club/programm/_archive_common" %}
    {% endcache %}
{% endif %}
</code></pre>

<p>thanks for all the fish!<br>
stefan</p>

<cache>
On a Archive: how could I break cache for the current year, but not the others?
# On a Archive: how could I break cache for the current year, but not the others?

(Asked by: username_0 on 2014-09-09)

I have an archive of an event based site. 
I know how to break cache until the next event. No Problem
{% cache until nextEvent %}

But the archive works the following way: 
archive
-- 2014 (latest year)
-- 2013
-- 2012
-- 2011  
The until nextEvent part makes only sense for the latest year. The other years should be cached forever. 
How could I achieve such a thing? 
-- edit --
Maybe I have to go a little more into the details:
I get the year in the forth segment.
Now it should cache the whole loop and never break it, unless it's the actual year, then break it each night: 
{% set latestYear = now|date("Y") %}

{% if year is not defined %}
    {% redirect "club/programm/archiv/"~latestYear %}
{% endif %}

{% set year = craft.request.getSegment(4) %}

{# Set the first day of the year and the last #}
{% set lastyear = year -1 %}
{% set nextyear = year +1 %}
{% set yearbegins = '1 January ' ~ year %}
{% set yearends = '1 January ' ~ nextyear %}
{% set unixbegins = yearbegins | date('U') %}
{% set unixends = yearends | date('U') %}

{# Today at 00:00 #}
{% set today = now|date("Y-m-d") ~ ' 00:00' %}
{% set tomorrow = now|date_modify("+1 day")|date("Y-m-d") ~ ' 00:00' %}

{% set entriesByYear = craft.entries.section('programm').limit(null).cf_date('and', '>= ' ~ unixbegins, '< ' ~ unixends, '< ' ~ today| date("U")) %} {# '> just to make syntax highlighting correct #}

{% cache until tomorrow %}
    {% for month, entries in entriesByYear | group("postDate|date('F')") %}

        {# MONTHLY HEADER #}
        
            
                {{ month }} {{ year }} 
            
        

        {# ENTRIES PER MONTH #}
        {% for entry in entries %}

             
                {% include "programm/_common" %}                    
            
            
        {% endfor %}
    {% endfor %}
{% endcache %}

maybe that helps someone to help me ;)
cheers
stefan
--- edit 2 and solution --- 
so after the comments of victor I updated the code. and it works like a charm: 
{% set latestYear = now|date("Y") %}

{% if year is not defined %}
    {% redirect "club/programm/archiv/"~latestYear %}
{% endif %}

{% set year = craft.request.getSegment(4) %}

{# Set the first day of the year and the last #}
{% set lastyear = year -1 %}
{% set nextyear = year +1 %}
{% set yearbegins = '1 January ' ~ year %}
{% set yearends = '1 January ' ~ nextyear %}
{% set unixbegins = yearbegins | date('U') %}
{% set unixends = yearends | date('U') %}

{# Today at 00:00 #}
{% set today = now|date("Y-m-d") ~ ' 00:00' %}
{% set tomorrow = now|date_modify("+1 day")|date("Y-m-d") ~ ' 00:00' %}

{# Get the Date of the next Event, to allow caching until then #}
{% set nextEvent = craft.entries.section('programm').cf_date('>= ' ~ today| date("U")).order('cf_date asc').first() %}{# '> just to make syntax highlighting correct #}
{% set nextEventDate = nextEvent.cf_date|date_modify("+1 day")|date("Y-m-d") ~ ' 00:00' %}

{# Get all the events within the year concerned #}  
{% set entriesByYear = craft.entries.section('programm').limit(null).cf_date('and', '>= ' ~ unixbegins, '< ' ~ unixends, '< ' ~ today| date("U")) %} {# '> just to make syntax highlighting correct #}

{# If the year is the current year, cache it until the next event. Otherwhise, cache indefinitely #}
{% if year == latestYear %}
    {% cache until nextEventDate %}
        {% include "club/programm/_archive_common" %}
    {% endcache %}
{% else %}
    {% cache %}
        {% include "club/programm/_archive_common" %}
    {% endcache %}
{% endif %}

thanks for all the fish!
stefan

**Tags:** cache


---

## 1 answers

### Answer by username_1 on 2014-09-09. Score: 1

You could use the new [Cold Cache pluging from P&T](https://github.com/pixelandtonic/ColdCache/) which:

> Adds a new `{% coldcache %}` tag to Craft, which works just like Craft’s
> built-in `{% cache %}` tag, except that this tag won’t record which
> elements and element queries are active between its tags. The only way
> caches will ever get deleted is if they expire, or an admin clears
> them using the Clear Caches tool in Settings.

> **Comments:**
> **username_0**: I know that coldcache exists, but that doesn't solve the problem, or does it?  
> **username_1**: I don't know how your template looks, but I would create two for-loops: One for the current year (and wrap it in `{% cache until nextEvent %}`) and one for everything else (`{% coldcache %}`).  
> **username_0**: just after posting my remark, I understood what you meant... I've updated the question as well. Two loops would be an option - you are completely right... I wish there was a way with only one loop, but I guess it's OK like you proposed... btw: don't really need coldcache, I just don't want to break it every night... cheers  
> **username_1**: @username_0 Now I understand that you have a separate page for each year. Why don't you just use `{% cache %}`? It will be saved for each page separately and only cleared when an entry matching that query gets updated.  
> **username_0**: no, since it's event based, the events are only going into the archive after a certain date, not when they are edited! that's what it's all about... I will update the question with the answer. that I actually found because of your initial comment ;)  
> **username_1**: @username_0 Glad you got it sorted ;)  

---

