Hi, 
I'm wondering if it would be a good idea to have fragment cache to allow 
options :if / :unless to determine whether or not to actually perform 
caching on the given block.

It would actually be a good idea in my opinion right now, since I'm working 
on a piece of code that would benefit by this feature. 

The scenario is the following: 

I have a partial, which is conditionally requiring other partials inside. 
The first line of this partial starts with a `cache(key) do` declaration, 
but some of the nested partial can't basically be cached due to the nature 
of the content. 

I could obviously wrap every nested partial call inside a cache for itself. 
This is technically not the same in terms of performance gain (not all 
computations inside the main partial would be cached) and it would probably 
be more clean to have something like this (trivialized): 

<%= cache(@model, unless: content_cachable?(@model)) do %> 
  <% if @model.render_good? %> 
    <%= render 'good_one' %> 
  <% else %> 
    <%= render 'bad_one' %> 
  <% end %> 
  ... other tens of similar conditions

<% end %>

This may reveal some bad partial design I'm facing, but I'm curious to know 
what you guys think about it. 

-f

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/LH35Qn-HOmEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to