cache_trasher ============ When using page caching, often you'll need to expire several pages in several locations at once. cache_trasher provides a simple method for bulk-deleting cached pages via action, controller, or direct path. Example ======= cache_trasher should be used in place of expire_page in your cache sweepers. class PageSweeper < ActionController::Caching::Sweeper observe Page def after_save(page) # deletes public/pages and public/pages.html (if it exists) # note that this uses url_for, so the documentation for url_for paths applies: # # If the controller name begins with a slash no defaults are used: # url_for :controller => '/home' # In particular, a leading slash ensures no namespace is assumed. Thus, while url_for :controller => 'users' # may resolve to Admin::UsersController if the current controller lives under that module, url_for :controller => '/users' # ensures you link to ::UsersController no matter what. trash_cache(:controller => "pages") # => may resolve to admin/pages if there happens to be a pages controller in the admin namespace # ensure no namespace when trashing the pages cache trash_cache(:controller => "/pages") # deletes public/pages/view and public/pages/view.html (if it exists) trash_cache(:controller => "pages", :action => "view") # deletes public/index.html trash_cache("index") # deletes public/bio.js trash_cache("bio", :format => :js) # deletes public/bio.js and public/bio.html trash_cache("bio", :format => [:js, :html]) # deletes your entire cache provided config.action_controller.page_cache_directory is not your public directory trashes_cache() end end Note that trash_cache will never delete your entire public directory or everything in your public directory. However, it will delete pretty much anything else you tell it to regardless of whether or not it's actually a cached file, so be careful! Copyright (c) 2008 factor[e] design initiative, released under the MIT license
Project
cache_trasher
Convenience methods for removing page cache files in Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Development
Dependencies
Project Readme