Re: reason for action_cache before_filter?

Gustav Paul
Sat, 25 Nov 2006 22:10:07 -0000

Thanks Tom!

I''ve since figured this out after long hours of sweating over a plugin!
:]

I asked because I wanted to start working on a plugin (patch?) that''d
let
you keep multiple versions of an action_cached page. I''ve since opted
for an around_filter approach (which also circumvents the code in the
action of course ;] ), and its working beautifully! At the moment the
syntax looks as follows:

class WelcomeController < ApplicationController

  cache_filter :index, :faq do | cache |
    if cache.session[:logged_in]
      cache.as :logged_in
    else
      cache.as :logged_out
    end
  end

  def index
  end

  def faq
  end

end

Anyway, I''ve finished it earlier this evening and applied to have the
plugin kept
at rubyforge. I''ll post to the list once its checked in.

Thanks again for the help man! When I started out I though
action_caching would
still execute the code in the action (now it seems so obvious that it
shouldn''t, but
back then it wasn''t :] ) but just serve the rendered tempalte from
cache
instead of
doing all the ERb stuff etc...

This is the first time I''ve gone peeking into the rails source, which
has given me a
new found respect for all the contributors!

Anyway, thanks again,

Cheery-o
Gustav Paul
gustav-PUm+PnBUKx7YkQIYctQFYw@public.gmane.org

Tom Fakes wrote:
> The whole point of the Action Cache is to avoid executing the action.
>
> With your modifications, the action is always executed.  The purpose of
> the before_filter is to send the cached result instead of executing the
> action - the ''false'' line tells Rails to stop executing
filters and not
> call the action method.  If you remove the before_filter code, the
> action will always execute.
>
>
> >
>
>