Forum: Ruby on Rails Page cache and query string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
510a407ca30f1a12680ac897aae8cfed?d=identicon&s=25 Massimiliano Mirra - rails list (Guest)
on 2006-04-11 16:12
(Received via mailing list)
I've read about the problems of using page cache when there's a query
string, i.e. /article/list?page=1 will cache /article/list.html, then
/article/list?page=5 will retrieve /article/list.html regardless of
query string.

I'm using a workaround, it looks almost obvious but since I haven't
found it mentioned anywhere I'm afraid there's some equally obvious
drawback that I'm missing.  If that's the case, could anyone familiar
with caching in Rails please point it out?

Basically I'm having the web server rewrite URLs of the form
http://www.site.com/foo/bar?a=b to
http://www.site.com/foo/bar/query/a=b.  Then in config/routes.rb there
is:

  map.connect('foo/bar/query/:query_string',
    :controller => 'foo',
    :action => 'bar')

In foo_controller.rb:

  class FooController < ApplicationController
    caches_page :bar
    before_filter :merge_query_string

    def bar
      render :text => "You asked for #{params.inspect}"
    end

    private

    def merge_query_string
      params[:query_string] or return

      params.
        update(CGIMethods.parse_query_parameters(params[:query_string])).
        delete(:query_string)
    end
  end

When a request comes for /foo/bar?a=b, it is cached as
/foo/bar/query/a=b, and when it comes for /foo/bar?a=x, it is cached
separately as /foo/bar/query/a=x.  Apparently it's working.  Where's
the catch?

Thanks for any insight.
Massimiliano
This topic is locked and can not be replied to.