views:

139

answers:

1

Hi,

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)

+1  A: 

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().

jonnii
I knew I would felt like the answer is so obvious ;-)Thanks buddy!
No problem, sometimes you just need someone to point out the obvious because you're too caught up in other things. It happens to me all the time ;)
jonnii