Permalink
Browse files

added cache sweeper for indicators

  • Loading branch information...
1 parent 6fc34d1 commit 05c6a612a71a4cacb1496876f4f29d6684d09677 @agnessa agnessa committed Apr 17, 2012
Showing with 26 additions and 1 deletion.
  1. +24 −0 app/controllers/indicator_sweeper.rb
  2. +2 −1 app/controllers/indicators_controller.rb
@@ -0,0 +1,24 @@
+class IndicatorSweeper < ActionController::Caching::Sweeper
+ observe Indicator
+
+ def after_create(indicator)
+ expire_cache_for(indicator)
+ end
+
+ def after_update(indicator)
+ expire_cache_for(indicator)
+ end
+
+ def after_destroy(indicator)
+ expire_cache_for(indicator)
+ end
+
+ private
+ def expire_cache_for(indicator)
+ # Expire the index page now that we added a new indicator
+ expire_page(:controller => 'indicators', :action => 'index')
+
+ # Expire a fragment
+ #expire_fragment('all_available_indicators')
+ end
+end
@@ -1,5 +1,6 @@
class IndicatorsController < ApplicationController
- #caches_page :index
+ caches_page :index
+ cache_sweeper :indicator_sweeper
def index
@indicators = Indicator.all

0 comments on commit 05c6a61

Please sign in to comment.