Hi Railers, I am trying to create a simple application like a guest book which has users and uses sessions to keep track of which users are logged on. The user''s page is constructed after doing some SQL queries and the user clicks on another link and hits the back button I dont want to regenerate the whole page (which is what happens now) .So I want to use some kind of caching mechanism. The page caching doc clearly says that this works for only stateless pages.But again the example mentions a page which can be cached ''weblog/show/5 '' .The user''s home page url in my guestbook is a page which looks like /users/index/5 (5 is the unique user id). So does this mean I can use page caching? If not is there any other approach ? Vivek -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060110/7aab3ec3/attachment.html
On 1/9/06, Vivek Krishna <krishna.vivek@gmail.com> wrote:> Hi Railers, > I am trying to create a simple application like a guest book which has users > and uses sessions to keep track of > which users are logged on. The user''s page is constructed after doing some > SQL queries and the user clicks on another link and hits the back button I > dont want to regenerate the whole page (which is what happens now) .So I > want to use some kind of caching mechanism. > The page caching doc clearly says that this works for only stateless > pages.But again the example mentions a page which can be cached > ''weblog/show/5 '' .The user''s home page url in my guestbook is a page which > looks like > /users/index/5 (5 is the unique user id). > So does this mean I can use page caching? > If not is there any other approach ? > VivekPage caching means that for weblog/show/5, it writes this file in your public directory: public/weblog/show/5.html Assuming you have your webserver set up correctly, it will then serve this file instead of hitting rails. I do a lot with page caching (probably more than is healthy), and have been writing a little series on the subject with Courtenay on the caboose blog: http://blog.caboo.se/articles/2005/12/16/page-caching-your-whole-app http://blog.caboo.se/articles/2005/12/27/when-page-caching-goes-bad-horribly-bad http://blog.caboo.se/articles/2006/01/07/referenced-page-caching As always, consult the docs for more info. You can also look into action and fragment caching, which work well too. -- rick http://techno-weenie.net
Vivek, I do this by using fragment caching, e.g.: <% cache( :action => ''fragment_identifier'', :controller => ''controller'', :action_suffix => ''unique_suffix'' %> @content_for_cache <% end %> In my case I cache pages based on where a user is logged in from (it''s a location-based service), and cache different pages for users who are admins vs. those who are not, so my action suffix looks like: get_current_place.id.to_s + "-" + get_current_user.admin?.to_s I can then expire both admin/non cached pages using the regexp version of expire_fragment: expire_fragment(/controller\/method.action_suffix=#{get_current_place.id.to_s*/) There may be better ways to do this, I''m relatively new to the Rails caching framework, but this should at least work for you. In your case, I"m not sure how much use you''ll get out of caching unless your app causes user to refresh regularly. I know that LiveJournal gets some use out of what could be considered per-user page caching, but that''s because their users are OCD and refresh their browsers habitually, which is not typical of most sites. Best of luck to you either way. pt. On 1/9/06, Vivek Krishna <krishna.vivek@gmail.com> wrote:> Hi Railers, > I am trying to create a simple application like a guest book which has users > and uses sessions to keep track of > which users are logged on. The user''s page is constructed after doing some > SQL queries and the user clicks on another link and hits the back button I > dont want to regenerate the whole page (which is what happens now) .So I > want to use some kind of caching mechanism. > The page caching doc clearly says that this works for only stateless > pages.But again the example mentions a page which can be cached > ''weblog/show/5 '' .The user''s home page url in my guestbook is a page which > looks like > /users/index/5 (5 is the unique user id). > So does this mean I can use page caching? > If not is there any other approach ? > Vivek > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Parker Thompson http://www.parkert.com/ 510.541.0125
Thanks for the suggestions. On 1/10/06, Parker Thompson <parkert@gmail.com> wrote:> > Vivek, > > I do this by using fragment caching, e.g.: > > <% cache( :action => ''fragment_identifier'', > :controller => ''controller'', > :action_suffix => ''unique_suffix'' > %> > @content_for_cache > <% end %>Parker, Where exactly should this be in the view ? I presume in my case the unique_suffix will be the user id! and Rick What does "First, remove all user-referencing erb code from the views." mean? I use a @user instance variable to show many things like name and other details.If I do remove then it becomes a stateless page anyway! Thanks for the link to the blog btw..It has a lot of other useful tips. Vivek -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060110/efcb760a/attachment.html
> and Rick > What does > "First, remove all user-referencing erb code from the views." mean? > I use a @user instance variable to show many things like name and other > details.If I do remove then it becomes a stateless page anyway! > > Thanks for the link to the blog btw..It has a lot of other useful tips. > VivekExactly what you said. You''d have to do some javascript trickery then. Or use some combination of fragment/action caching. -- rick http://techno-weenie.net
I tried some very simple page caching to get used to the idea. But it didnt generate any pages in the public/ directory. All I did was caches_page :index In def login # do authorization and set a sessiion redirect_to :action=>''index'' end def index # get the session and set a variable like @username render :action =>''index'' end I know the cache would probably get overwritten because its not unique for each user but I dont see any generated html .Am i missing something ? I read that caching is disabled in the development mode (i use webrick) how do I enable it? Vivek On 1/10/06, Rick Olson <technoweenie@gmail.com> wrote:> > > and Rick > > What does > > "First, remove all user-referencing erb code from the views." mean? > > I use a @user instance variable to show many things like name and other > > details.If I do remove then it becomes a stateless page anyway! > > > > Thanks for the link to the blog btw..It has a lot of other useful tips. > > Vivek > > Exactly what you said. You''d have to do some javascript trickery > then. Or use some combination of fragment/action caching. > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060110/185cc096/attachment.html
On 1/10/06, Vivek Krishna <krishna.vivek@gmail.com> wrote:> I tried some very simple page caching to get used to the idea. But it didnt > generate any pages in the public/ directory. All I did was > caches_page :indexCaching only occurs in production mode. You can configure config/environment/development.rb to cache in dev mode. -- rick http://techno-weenie.net