caches_action and content_for blocks
Today, I realized that using content_for blocks as nice as they are make it much harder to cache. Typically, I won’t cache the layout for my actions so I would end up with a caches_action expression like the following:
caches_action :index, :layout => false, :expires_in => 10.minutes, :if => Proc.new {|c| c.send(:current_user).nil? }
However, I also started to add multiple yield blocks in my layouts. For example:
<!DOCTYPE html> <html> <head> ... <%= yield :head %> </head> <body> ... <%= yield %> ... <%= yield :sidebar %> ... <%= yield :foot %> </body> </html>
At first glance this is great! Now in each action/view I can customize specific components in my layout. The issue with this layout design and action_caching is that the content_for blocks do not appear to re-evaluate from the cached action into the ‘yield blocks’ in the layout. We could perhaps solve this with some modifications to content_for and some modifications around each ‘yield block’. I’m going to see if there is a solution and post… In the mean time does anyone have any suggestions?

Recent Comments