What is the best way to set up caching when GET parameters are
involved? For example I don’t want both /index and /index?
tags=example to be cached as index.html. Does that make sense?
Thanks,
Tom
What is the best way to set up caching when GET parameters are
involved? For example I don’t want both /index and /index?
tags=example to be cached as index.html. Does that make sense?
Thanks,
Tom
You can always use a fragment caching approach and name your fragments
appropriately. Suppose its the index view of Projects…
def index
@param_string = massage_tags(params[:tags])
unless Rails.cache.exist?(‘views/project.index.’+@param_string)
@projects = Project.find(blah blah blah)
end
end
index.html.erb
<% cache(‘project.index.’+@param_string) do %>
<% @projects.each do |project| %>
blah blah blah
<% end %>
<% end %>
Pagination will throw a wrinkle in this, as you’ll want a cache per page
possibly, and create/edit/delete of an arbitrary project will
essentially invalidate all the caches for that model, unless you do some
logic I don’t even want to think about.
To save some processing time, you could cache just the index row for
each project and save that rendering time. If you display 30 projects on
the index form, and only 1 on the current page has changed (either via
addition, editing, or deletion), you’ll at least save the rendering on
the other 39… whether that is worthwhile depends on what data you are
showing.
YMMV
Ar Chron wrote:
Er, ignore my math.
30 per page, edit/change 1, save rendering on 29, not 39… Doh!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs