Caching, Collections, Rails 5, multiple views colliding

I have a Thing object that can be presented in two ways depending on whether you are in the main controller or the list controller.

main/_thing.rb

list/_thing.rb

I can cache both of these without them clobbering each others’ keys

main/_thing.rb

<% cache [“main”,thing] do %>

-stuff-

<% end %>

and

list/_thing.rb

<% cache [“list”,thing] do %>

-stuff-

<% end %>

Rails 5 has the shiny new cache capability for collections

<%= render partial: “main/thing”, collection: myThings, cached: true %>

this works great

however I’d also like to the same approach in my list view with

<%= render partial: “list/thing”, collection: myThings, cached: true %>

but now I have conflicting keys and everything goes squirly. I think because the cache key is generated on Thing and doesn’t ‘realise’ that I’m using different presentation logic.

there is one hint of an error I get

‘Couldn’t find template for digesting: list/_thing’

I don’t understand this error; list/_thing.html.erb definitely does exist.

I can’t for the life of me figure out how to get a custom cache key (and for a while I accidentally broke production before realising the issue here).

The relevant rails code is here I think

https://github.com/rails/rails/blob/cf5bc0dd5359e61dcb93e719279c7198e68a0eb8/actionview/lib/action_view/helpers/cache_helper.rb

and it looks like this should be possible.

I have tried

cached: → myThings { [ myThings, “list” ] }

and

cached: [myThings, “list” ]

but those were really just guesses as I don’t understand the logic

I’m running rails 5.0.6

can anyone help?

thank you.

Rob