Caching

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   # massage your params tags into a usable form (implementation   # is left as an exercise for the reader - 'example' in a simple   # case, or some ugly string if you support multiple tags, and   # perhaps "base" if no tags exist in params)   @param_string = massage_tags(params[:tags])   # if you have it cached, don't bother with the read   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!