user62605
user62605

Reputation: 185

Rails - Best way to implement Optionnal Fragment Caching for testing purposes

I'm using fragment caching a lot and it is essential to me for good performance. However, due to the complexity of the caching I'm using, I need to offer my testers, a way to disable/enable caching as a session variable. (On a user basis only)

I was thinking about implementing a cache_disabled? method, and I now check for it's value everywhere I use cache. Now, I'm stuck with the following piece of caching, and I can't figure out how to nicely integrate this check :

<% cache(@cache_key_for_consultContent) do %>
     <div id="consult">
              <%= render :partial => 'LOTS_OF_CONTENT' %>
     </div>
<% end %>

I need the content to be called when caching is disabled or content isn't cached yet.

thanks for your creativity! (Please keep it DRY)

Upvotes: 2

Views: 446

Answers (1)

jonnii
jonnii

Reputation: 28312

In your application helper you could try:

def optional_cache(key, &block)
  cache(key, &block) unless session[:disable_caching]
end

Then replace your calls to cache() with optional_cache().

Upvotes: 3

Related Questions