开发者

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 creativ开发者_JAVA技巧ity! (Please keep it DRY)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜