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 %}
  • 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? – Ben Shoults Feb 5 '16 at 14:47
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.

| improve this answer | |
  • 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? – David Oliver Sep 19 '16 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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