On 8/18/06, Ross Riley <riley.ross@gmail.com>
wrote:>
> Hello.
>
> I wouldn''t mind getting some feedback about the use of fragment
> caching. I''ve got a series of relatively expensive database
queries
> with their respective partials cached and everything is working fine.
>
> The problem is that do get this to work I''ve had to move the
database
> queries from the controller into the view layer so as to avoid them
> being called if the partial is cached. Is this the way that you guys
> handle this problem, as obviously while essential for performance it
> breaks the view accessing the model golden rule.
>
> I was wondering if anyone has a better way of handling this scenario.
>
> Thanks
> Ross
>
Welcome to the real world of caching. :-) The agile book does discuss this
briefly, and it''s the method I have used so far (successfully, I
think).
Here''s the example they give:
class BlogController < ApplicationController
def list
@dynamic_content = Time.now.to_s
unless read_fragment(:action => ''list'')
logger.info("creating fragment")
@articles = Article.find_recent
end
end
end
You can skip the expensive database lookup or whatever by testing the output
of read_fragment. The golden rule has been restored, long live the golden
rule!
--
Jim Kane
fastjames@gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060818/49f7f1a0/attachment.html