scooterrr
2008-Sep-24 05:03 UTC
caches_page :if not executing (but caches_action :if) does
Hi folks - Seeing a weird problem and would love some help. It''s documented in http://pastie.org/278310 to be more readable. In short, I have a caches_page "action", :if => {stuff} but the :if is never being called - the action is just caching every time. (If I put a debugger call in the :if block, it never stops.) If I replace caches_page with caches_action, the if evaluates correctly. There are before_filters in the controller, but they do not apply to this action. (There''s one in the supercontroller but it seems similarly irrelevant - just trims www. from URLs.) What am I missing? Did I uncover an :if bug (which I doubt) or am I misunderstanding? Full example (also in pastie): #In this case, the :if is ignored, and all pages cache class PagesController < ApplicationController caches_page :show, :if => Proc.new {|c| ["home", "something- else"].index(c.request.path_parameters["id"])} before_filter :admin_required, :only => [ :index, :new, :create, :delete, :edit, :update ] before_filter :IP_restricted, :only => [ :index, :new, :create, :delete, :edit, :update ] #In this case, the :if executes correctly class PagesController < ApplicationController # just changing caches_page to caches_action works caches_action :show, :if => Proc.new {|c| ["home", "something- else"].index(c.request.path_parameters["id"])} before_filter :admin_required, :only => [ :index, :new, :create, :delete, :edit, :update ] before_filter :IP_restricted, :only => [ :index, :new, :create, :delete, :edit, :update ] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Sep-24 16:34 UTC
Re: caches_page :if not executing (but caches_action :if) do
Page caching (after the first access to a page) will write out a straight HTML file in /public/model/action.html to be found on any subsequent requests to that URL. Subsequent requests to that URL will hit the cached page only, without ever invoking Rails. The notion of caches_page ''action'', :if =>{stuff} is a non-starter. caches_action always invokes Rails and runs your filters et al, hence the working :if => {stuff} Check out http://www.railsenvy.com/2007/2/28/rails-caching-tutorial for an excellent tutorial on caching. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
scooterrr
2008-Sep-24 16:54 UTC
Re: caches_page :if not executing (but caches_action :if does)
I''m confused by this. I get why once the page is cached that Rails won''t execute again, but before the first cache attempt when Rails does run, the :if should fail. There''s documentation on caches_page ''action'', :if => {}, so I know I''m not making up that format. So I''m still confused. On Sep 24, 9:34 am, Ar Chron <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Page caching (after the first access to a page) will write out a > straight HTML file in /public/model/action.html to be found on any > subsequent requests to that URL. > > Subsequent requests to that URL will hit the cached page only, without > ever invoking Rails. The notion of caches_page ''action'', :if =>{stuff} > is a non-starter. > > caches_action always invokes Rails and runs your filters et al, hence > the working :if => {stuff} > > Check outhttp://www.railsenvy.com/2007/2/28/rails-caching-tutorialfor > an excellent tutorial on caching. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Sep-24 20:58 UTC
Re: caches_page :if not executing (but caches_action :if doe
Well... the caches_page in my action_controller/caching/pages.rb uses an after_filter def caches_page(*actions) return unless perform_caching options = actions.extract_options! after_filter({:only => actions}.merge(options)) { |c| c.cache_page } end whereas the caches_action in my action_controller/caching/actions.rb uses an around_filter def caches_action(*actions) return unless cache_configured? options = actions.extract_options! around_filter(ActionCacheFilter.new(:cache_path => options.delete(:cache_path)), {:only => actions}.merge(options)) end Perhaps the caches_page should be an around_filter as well??? (This is an absolute shot-in-the-dark on my part) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---