Forum: Ruby on Rails Fragment caching and pagination

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.
Steve O. (Guest)
on 2006-02-01 00:48
(Received via mailing list)
I'm just getting my hands dirty with caching. The pages I want to cache
have
some user specific data on them (for example "log out"). That sent me
down
the route of fragment caching. One of the things I want to pagination is
a
paginated list. My question is how is pagination and query strings
handled
with fragment caching? Does each page get its own fragment and query
string
identifier?

thanks,

Steve
http://www.smarkets.net
Alain R. (Guest)
on 2006-02-01 14:49
(Received via mailing list)
Steve
    >..  how is pagination and  query strings handled with fragment
caching?
    >  Does each page get its own fragment and query string identifier?

Yes. Each page related fragment is cached separately.

Here is what works for me:


In the view: (event/list.rhtml, a paginated view, with an optional
'year' filter. )

    line 1:   <% cache(:controller => 'event', :action => 'list', :group
=> visitor.group, :page => params[:page], :year => params[:year]) do%>
              ...

In the Controller:
    class EventController < ApplicationController
        cache_sweeper   :event_sweeper, :only => [:edit, :update, :new,
:create, :destroy]
       ...

In the sweeper:
    class EventSweeper <  ActionController::Caching::BaseSweeper
        observe Event

        def after_save(record)
            expire_fragment  %r{event/list.*}
            expire_home_page
        end
        def after_destroy(record)
            expire_fragment  %r{event/list.*}
            expire_home_page
        end

end
Steve O. (Guest)
on 2006-02-01 14:49
(Received via mailing list)
Excellent. Just what I was looking for.

Steve
This topic is locked and can not be replied to.