1

When using the {% cache %} tag on an entry type, it caches the first entry on the page (multiple pages as well), and uses the cached entry for every other instance of that entry type on the page. What am I doing wrong? Here's an example. This one isn't complex so not sure it's worth caching, but I have some entries that have multiple relational fields.

{% for block in entry.contentMatrix %}
  {% if block.type == "copyOneCol" %}
    {% cache %}
        .... output entry type data
    {% endcache %}

  ...next if, etc.
{% endfor %}
1
  • Ok, I'm using {% cache using key block.id %} and that is tentatively working, giving each section it's own cache (I'm assuming). Is this the best way to do this? Feb 5, 2016 at 14:47

1 Answer 1

1

Correct... by default the {% cache %} tag will use the current page's URI (including querystring) for the cache key. If you want to change that behavior you'll need to specify the using key parameter and supply a unique key. Although you might want to make something more unique than just block.id as that will be an integer and could potentially easily be overwritten.

1
  • In response to 'Although you might want to make something more unique than just block.id as that will be an integer and could potentially easily be overwritten.' Based on inspecting the templatecaches table, the path is still recorded in the 'path' column, and the (potentially custom) 'cacheKey' is stored in its cacheKey column. So am I right in thinking that even if a custom key is set, the path will still be checked in addition to the custom key when drawing from the cache? Sep 19, 2016 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.