action_cache plugin now does expire_action

November 26, 2006 Link to post  Permalink

My action_cache plugin was kind of broken for the expire_action call. I’ve now implemented expire_action in a way that will work with custom cache keys provided by your code. This code uses the Regexp verson of the expire_fragment method to clean up, so you don’t have to be very precise when providing the options parameter to the expire_action call (unlike the base Rails code)

This also has the advantage of working with REST actions that can provide many different formats. You only need to know the base parameters you used to cache an action and all generated formats will be expired.

To help with this, I had to re-implement the way the cache key is generated. If you’ve implemented a custom fragment_key callback, you will need to change your code to now implement action_fragment_key on your application controller, and process the options hash to override the current controller values so expire_action works. I’ll post on one way to do this later.

I also added a new method – expire_all_actions – to clear the entire cache in a single call.

Thanks to Dan for pushing me to get this done. It turns out I need expire_action to work on other projects too.