I''m attempting to use caches_page to speed up the loading of certain pages on my site, and have run into a couple questions: 1) The site has ''states'' (as in U.S. states), so I have a State model and a States controller. Going to http://sitename/states/ routes you to the States controller, ''index'' action. The States controller looks like so: class StatesController < ApplicationController caches_page :index, :list, :show def index list render_action ''list'' end def list @page_title = ''States'' @states = State.find_all end [..snip...] end If I load the page, I get the following in the log: Rendering layouts/layout (200 OK) Cached page: /states.html Subsequent requests for the page show the same thing... it''s not using the cached page. Why is this? (Actually, now that I think about it, it''s probably because I''m rewriting the ''index'' action to ''list''. I''ll try changing that to see if it fixes it.) 2) Has anyone used caches_page with the pagination helper? When I try it, it caches page #1, and then requests for subsequent pages using the pagination links continue to serve the cached page #1 (this is expected, I suppose). What can I do to cache these pages? Thanks, Myles
Myles Grant wrote:> I''m attempting to use caches_page to speed up the loading of certain > pages on my site, and have run into a couple questions: > > 1) The site has ''states'' (as in U.S. states), so I have a State model > and a States controller. Going to http://sitename/states/ routes you > to the States controller, ''index'' action. The States controller looks > like so: > > class StatesController < ApplicationController > caches_page :index, :list, :show > > def index > list > render_action ''list'' > end > > def list > @page_title = ''States'' > @states = State.find_all > end > > [..snip...] > end > > If I load the page, I get the following in the log: > > Rendering layouts/layout (200 OK) > Cached page: /states.html > > Subsequent requests for the page show the same thing... it''s not using > the cached page. Why is this? (Actually, now that I think about it, > it''s probably because I''m rewriting the ''index'' action to ''list''. > I''ll try changing that to see if it fixes it.)Unfortunately, this didn''t change things. Maybe I''m missing some routing/mod_rewrite magic?> > 2) Has anyone used caches_page with the pagination helper? When I try > it, it caches page #1, and then requests for subsequent pages using > the pagination links continue to serve the cached page #1 (this is > expected, I suppose). What can I do to cache these pages? > > Thanks, > Myles > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-Myles
On 27.4.2005, at 23:04, Myles Grant wrote:>> >> If I load the page, I get the following in the log: >> >> Rendering layouts/layout (200 OK) >> Cached page: /states.html >> >> Subsequent requests for the page show the same thing... it''s not >> using the cached page. Why is this? (Actually, now that I think >> about it, it''s probably because I''m rewriting the ''index'' action to >> ''list''. I''ll try changing that to see if it fixes it.) > > Unfortunately, this didn''t change things. Maybe I''m missing some > routing/mod_rewrite magic?It seems that routes and caches_page are not playing together that well. You see that the page is cached as /states.html. However, the page called was /states and your web server doesn''t understand that it means states.html. So actually the page should be cached as /states/index.html in order for it to work right. One way around this bug would be to configure your webserver to try also /name.html for every request for /name. Unfortunately this doesn''t help you too far if you have some custom routes since the way the files are stored in the file system is always /controller/action/id and so on. For example I had a page /fi/products which was routed to controller=page&action=show&id=products&lang=fi. Page caching was storing it in /page/show/products/fi/index.html IIRC so the cached file was never used. Therefore I turned back to action caching for now, because it seemed a lot wiser with regard to routes. //jarkko> >> >> 2) Has anyone used caches_page with the pagination helper? When I >> try it, it caches page #1, and then requests for subsequent pages >> using the pagination links continue to serve the cached page #1 (this >> is expected, I suppose). What can I do to cache these pages? >> >> Thanks, >> Myles >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > -Myles > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko Laine wrote:> On 27.4.2005, at 23:04, Myles Grant wrote: > >>> >>> If I load the page, I get the following in the log: >>> >>> Rendering layouts/layout (200 OK) >>> Cached page: /states.html >>> >>> Subsequent requests for the page show the same thing... it''s not >>> using the cached page. Why is this? (Actually, now that I think >>> about it, it''s probably because I''m rewriting the ''index'' action to >>> ''list''. I''ll try changing that to see if it fixes it.) >> >> >> Unfortunately, this didn''t change things. Maybe I''m missing some >> routing/mod_rewrite magic? > > > It seems that routes and caches_page are not playing together that > well. You see that the page is cached as /states.html. However, the > page called was /states and your web server doesn''t understand that it > means states.html. So actually the page should be cached as > /states/index.html in order for it to work right. > > One way around this bug would be to configure your webserver to try > also /name.html for every request for /name. Unfortunately this > doesn''t help you too far if you have some custom routes since the way > the files are stored in the file system is always > /controller/action/id and so on. > > For example I had a page /fi/products which was routed to > controller=page&action=show&id=products&lang=fi. Page caching was > storing it in /page/show/products/fi/index.html IIRC so the cached > file was never used. Therefore I turned back to action caching for > now, because it seemed a lot wiser with regard to routes. > > //jarkko >I have a default route that points to :controller => ''site'', :action => ''index'', and caches_page is smart enough to put that as ''/public/index.html''. Also, calling the page ''http://site/states/show/1'' puts a cached file in ''/public/states/show/1.html''. Seems like ''http://site/states/'' should put the cached file in ''/public/states/index.html''. This is either a bug or I''m missing an option. I''ll dive into the code to find out. -Myles>> >>> >>> 2) Has anyone used caches_page with the pagination helper? When I >>> try it, it caches page #1, and then requests for subsequent pages >>> using the pagination links continue to serve the cached page #1 >>> (this is expected, I suppose). What can I do to cache these pages? >>> >>> Thanks, >>> Myles >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> -Myles >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >