Fragment Caching

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

On 8/18/06, Ross R. [email protected] wrote:

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. :slight_smile: 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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs