I have a problem with using {% cache %}in Craft 3, although the code runs fine without caching, and it works in Craft 2.
I have narrowed the problem down to the following code:
{% cache %}
{% set upcomingShows = craft.entries.section('shows').orderBy('showTime asc').limit(null).all() %}
{% for date, shows in upcomingShows|group("showTime|date_modify('-3 hours')|date('Y-m-d')") %}
{% for show in shows %}
{% set movie = craft.entries.relatedTo({ targetElement: show }).one() %}
{% endfor %}
{% endfor %}
{% endcache %}
It gives me the following fatal error:
Allowed memory size of 268435456 bytes exhausted (tried to allocate 71002178 bytes)
If I skip the Twig |groupfilter, the cache works again:
{% cache %}
{% set upcomingShows = craft.entries.section('shows').orderBy('showTime asc').limit(null).all() %}
{% for shows in upcomingShows %}
{% for show in shows %}
{% set movie = craft.entries.relatedTo({ targetElement: show }).one() %}
{% endfor %}
{% endfor %}
{% endcache %}
(I first thought the problem was the relatedTo() function, but it turns out it's the |group is what triggers it, without it it works also with the relatedTo().)
Is this a bug in the cache, or is there a way around it?
UPDATE: After some more testing, it seems like it works either with the |group filter or the relatedTo() function, but not both at the same time.
upcomingShowsquery? – Mats Mikkel Rummelhoff Jul 14 '18 at 20:27