Cache not cleared correctly when using {% cache until %} (CraftCMS 3.5.17.1) #13134
-
We have a theater site with a large event list. The events are rows in a table field inside entries from a “production“ section (190 entries in that section, 230 events across these entries). On the homepage, we display events for the next 3 days that have events. The program page displays all events. In both cases, only events today or in the future are displayed. Past events should be hidden. Overview
Problem Any ideas if my caching plan is flawed? Is there a chance that old results be cached? Or could the cache not expire as planned? _layout.twig {% set startOfToday = now|date_modify("00:00:01") %}
{% set endOfToday = now|date_modify("23:59:59") %} eventList.twig: {# Cache event list until 23:59:59 today #}
{% cache until endOfToday %}
{# stillRunning is a preparse field used to pre-filter only productions that had events in the future when they were last saved are queried. When a production entry is saved and all its events are in the past, stillRunning will be 0. This reduces the initial query because there are only around 30 active productions at any given time of the year. #}
{# productionEvents is a table field that has date and time field (this version of Craft didn’t have dateTime fields yet) #}
{% set allProductions = craft.entries()
.section("productions")
.stillRunning("1")
.with(["productionEvents:date", "productionEvents:time"])
.all()
%}
{# Merge date and time fields per event per production #}
{# Add all events to list that are after 00:00:01 today #}
{% set allEvents = [] %}
{% for production in allProductions %}
{% for event in production.productionEvents %}
{% set eventDate = event.date|date_modify(event.time|time()) %}
{% if eventDate > startOfToday %}
{% set allEvents = allEvents|merge([event]) %}
{% endif %}
{% endfor %}
{% set allEvents = allEvents|sort((a, b) => a.date|date_modify(a.time|time()) > b.date|date_modify(b.time|time())) %}
{% endfor %}
{# Output list here #}
{% for event in allEvents %}
{# … #}
{% endfor %}
{% endcache %} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
@jannisborgers I remember I had same issue with cache until on craft 3 and it resolved later on 3.6.12.1 #7826 |
Beta Was this translation helpful? Give feedback.
@jannisborgers I remember I had same issue with cache until on craft 3 and it resolved later on 3.6.12.1 #7826