Caching, Collections, Rails 5, multiple views colliding

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Caching, Collections, Rails 5, multiple views colliding

Rob Jonson
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.


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

<% cache ["main",thing] do %>
<% end %>


<% cache ["list",thing] do %>
<% 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

and it looks like this should be possible.

I have tried

cached: -> myThings { [ myThings, "list" ] }
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.


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit
For more options, visit