2

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)

user62605
  • 185
  • 1
  • 10

1 Answers1

3

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
  • 28,019
  • 8
  • 80
  • 108
  • I knew I would felt like the answer is so obvious ;-) Thanks buddy! – user62605 Jan 28 '10 at 16:34
  • 2
    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 Jan 28 '10 at 16:42