Mikhail Kornienko
2007-Jan-22 08:22 UTC
caches_action :index for site root gets propagated to lower levels (how to stop?)
Hello all, I am running a blog system which has its "/" (home page) cached like this: class ApplicationController < ActionController::Base before_filter :index_cache_expirer, :only => [:index] caches_action :index so the site''s top page is caches for 60 seconds in my case (index_cache_expirer is a home-made function to expire) on the site, there is also a multi-user /admin area, which in turn has its own controllers with :index action. The problem is that effect of "caches_action :index" directive, which is set inside the application.rb, somehow gets propagated to, say, :index action of admin/posts controller, which causes problems because a user is sometimes served by a page, which was cached by another user! (like, logging in and checking his own posts list, just to be served by a cached posts list, which was created for another user) I might not be doing the caching the right way or something, but is there a way to turn off that caches_action directive propagation to "lower" level of the site (i.e. just make it work ONLY for the application controller''s :index action, where it was defined in?) Any suggestions are very appreciated as my site is now running with caching off while I''m trying to find a good solution for the problem. TIA, Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Jan-22 20:03 UTC
Re: caches_action :index for site root gets propagated to lower levels (how to stop?)
> Hello all, > > I am running a blog system which has its "/" (home page) cached like > this: > > class ApplicationController < ActionController::Base > before_filter :index_cache_expirer, :only => [:index] > caches_action :index > > so the site''s top page is caches for 60 seconds in my case > (index_cache_expirer is a home-made function to expire) > > on the site, there is also a multi-user /admin area, which in turn has > its own controllers with :index action. > > The problem is that effect of "caches_action :index" directive, which > is set inside the application.rb, somehow gets propagated to, say, > :index action of admin/posts controller, which causes problems because > a user is sometimes served by a page, which was cached by another user! > (like, logging in and checking his own posts list, just to be served by > a cached posts list, which was created for another user) > > I might not be doing the caching the right way or something, but is > there a way to turn off that caches_action directive propagation to > "lower" level of the site (i.e. just make it work ONLY for the > application controller''s :index action, where it was defined in?) > > Any suggestions are very appreciated as my site is now running with > caching off while I''m trying to find a good solution for the problem.Well, *every* controller you have inherits from ApplicationController (see the "class" line at the top). So by putting this into ApplicationController you''re telling it to apply to *every* controller''s index action. Move that caches_action line out of ApplicationController and put it into whatever controller serves up your home page. -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mikhail Kornienko
2007-Jan-22 23:05 UTC
Re: caches_action :index for site root gets propagated to lower levels (how to stop?)
Philip, thank you very much! Indeed! Somehow I just didn''t happen to think about this inheritancy as the source of the problem! Now thinking about it, it is almost a miracle I didn''t have more problems with the program, since I have put pretty alot of various stuff inside the ApplicationController. Got to rebuild my app''s structure a little I guess. Thanks again! Mike. On Jan 23, 5:03 am, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > Hello all, > > > I am running a blog system which has its "/" (home page) cached like > > this: > > > class ApplicationController < ActionController::Base > > before_filter :index_cache_expirer, :only => [:index] > > caches_action :index > > > so the site''s top page is caches for 60 seconds in my case > > (index_cache_expirer is a home-made function to expire) > > > on the site, there is also a multi-user /admin area, which in turn has > > its own controllers with :index action. > > > The problem is that effect of "caches_action :index" directive, which > > is set inside the application.rb, somehow gets propagated to, say, > > :index action of admin/posts controller, which causes problems because > > a user is sometimes served by a page, which was cached by another user! > > (like, logging in and checking his own posts list, just to be served by > > a cached posts list, which was created for another user) > > > I might not be doing the caching the right way or something, but is > > there a way to turn off that caches_action directive propagation to > > "lower" level of the site (i.e. just make it work ONLY for the > > application controller''s :index action, where it was defined in?) > > > Any suggestions are very appreciated as my site is now running with > > caching off while I''m trying to find a good solution for the problem.Well, *every* controller you have inherits from ApplicationController (see > the "class" line at the top). So by putting this into > ApplicationController you''re telling it to apply to *every* controller''s > index action. > > Move that caches_action line out of ApplicationController and put it into > whatever controller serves up your home page. > > -philip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---