[ANN] Broomstick - Making Sweeping a Little Bit easer

Page sweeping just got a whole lot easier! Rails only offers methods to
expire a single page but no methods to expire an entire action or
controller. This plugin does just that.

This initial release of the plugin only adds one method
(expire_each_page() ) to your disposal. Hereâ??s a quick example and
exactly how it works.

expire_each_page(:controller => ‘pragmatic’, :action => ‘view’)

The above method will call url_for on the controller/action combo and
expire all pages that are under public/pragmatic/view/ and
public/pragmatic/view.html

expire_each_page(:controller => ‘pragmatic’)

The above method will call url_for on the controller and expire all
pages that are under public/pragmatic/ and public/pragmatic.html
To install this plugin just run:

script/plugin install http://svn.recentrambles.com/broomstick

SETUP INSTRUCTIONS

Make sure that this broomstick directory in under
your_app/vendor/plugins/
There are a couple of issues you will need to fix in your routes.rb and
your .htaccess or lighttpd.conf if you want to use this plugin. First
let fix your routes.rb. If your routes.rb has this line:

map.connect ‘’, :controller => “pragmatic”

you will need to add this line directly above it:

map.connect ‘/pragmatic’, :controller => “pragmatic”
map.connect ‘’, :controller => “pragmatic”

By adding the new line, you are telling rails to map all calls to
url_for(:controller => â??pragmaticâ??) back to /pragmatic. Without this the
exprire_each_page method will not work for your pragmatic controller
(the controller that holds your initial action) because it is mapped
back to â??/â??. This would cause the plugin to delete your entire public
directory. Donâ??t worry, if you forgot to change this you will see a very
nice long message in your logs and no files will be removed.

The second issue is directly related to this routes.rb change. By adding
this new map.connect statement, rails will stop caching an index.html
page. It will start caching a pragmatic.html page. This works great but
a new page will be created on each call because Apache is still looking
for index.html. To fix this we modify the public/.htaccess file so that
Apache will look for the pragmatic.html file instead of index.html. Here
are the modified lines in the .htaccess file. This:

RewriteRule ^$ index.html [QSA]
changes to this:
RewriteRule ^$ pragmatic.html [QSA]

If you are using lighttpd add this line:

url.rewrite = (
“^/$” => “pragmatic.html”,
“^([^.]+)$” => “$1.html” )

Thatâ??s all it takes to be able to do mass page expirations based on a
controller and or action.

Released under the same license as Ruby. No Support. No Warranty. Back
up your public directory (or whatever you have your rails cache
directory set to) before usingâ?¦I hope you already knew that!

Charlie B.
www.recentrambles.com

Available at http://agilewebdevelopment.com/plugins/show/88 :slight_smile:

And yes, I’ll be working on improving the format of the description.

unknown wrote:

Available at http://agilewebdevelopment.com/plugins/show/88 :slight_smile:

And yes, I’ll be working on improving the format of the description.

Thanks for posting the plugin, my next step was to set it up on your
site!