I think I am not fully understanding how caching works.
Based on this answer I thought I could cache my query and then shuffle the resulting array items.
So I ended up with this code:
{% cache %}
{% set categoryProducts = craft.entries.section('products').relatedTo(category) %}
{% endcache %}
{% set categoryProducts = shuffle(categoryProducts) %}
{% for entry in categoryProducts %}
...
{% endfor %}
But that does give me a "categoryProducts" does not exist
error.
Could someone shed some light as to why caching the query doesn't work? I thought caching tags help to reduce the amount of queries being made and I've been studying the documentation, but I don't seem to fully grasp the concept.
cache
tag needs to contain HTML output. If your query was included within the cached segment, then it will be recorded for cache-busting purposes, and not run again unless the data changes.