Tuesday, February 2, 2010

[Rails] Action Caching and After Filters

Hi there,

I'm using action caching, instead of page caching, because I'm using
filters in my controller.

<code>
class CommunityProgramController < ApplicationController

before_filter :login_required
after_filter :log_request

caches_action :show
</code>

In the log:
Cached fragment hit: views/site.com/community_programs/1 (0.2ms)
Filter chain halted as [#<ActionController::Filters::AroundFilter:
0x2a3a1540 ........

I'm wondering if there's a way to get after_filters working with
action caching. As far as I can tell what happens is, if an action has
been cached, the caches_action filter will halt the filter chain and
spit back the cached result. This means that any after_filters don't
get run.

Is there some way to still have the after filters run ?
Are my assumptions correct about how this is working ?

Yes, I know I could change it to a before filter. I've done a little
bit of performance testing and it appears that the gain I get in using
action caching is cancelled out by needing log_request to be a before
filter instead of an after filter.

Thanks!

Luke

--
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@googlegroups.com.
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.

No comments:

Post a Comment