title: Rails Cache Sweeper
body: <p>I'm trying to implement a Cache Sweeper which would filter a specific controller action.</p>
  
  <pre><code>class ProductsController &lt; ActionController  
      caches_action :index  
      cache_sweeper :product_sweeper  
  
      def index 
          @products = Product.all 
      end 
  
      def update_some_state
        #... do some stuff which doesn't trigger a product save, but invalidates cache
      end
  end 
  </code></pre>
  
  <p>Sweeper Class:</p>
  
  <pre><code>class ProductSweeper &lt; ActionController::Caching::Sweeper
      observe Product
  
      #expire fragment after model update
      def after_save
         expire_fragment('all_available_products')   
      end
  
      #expire different cache after controller method modifying state is called.
      def after_update_some_state
          expire_action(:controller =&gt; 'products', :action =&gt; 'index') 
      end
  end
  </code></pre>
  
  <p>The ActiveRecord callback 'after_save' will work fine, but the callback on the controller action 'after_update_some_state' never seems to be called.</p>