How do you clear cached actions in Rails?

November 17, 2006 Link to post  Permalink

Careful, this is a trick question!

The obvious thing is to call ‘expire_action’ to remove the cached entries for the specified action. However, the fragment cache path for an action includes the controller name, and the expire_action method is a method on the controller, so the only cached actions you can expire are ones on the current controller.

What this really means is that those of you with ‘Admin’ controllers have to pass the controller into the expire_action as part of the options hash. This is essentially the same as url_for(), because url_for() is the method used to build the fragment cache key.

Seems like this can be improved.

And an opportunity for my action_cache plugin to help out. More later.

Update: Changed some information, as I found how the action cache uses url_for.