caching - Rails Cache Sweeper -


i'm trying implement cache sweeper filter specific controller action.

class productscontroller < actioncontroller       caches_action :index       cache_sweeper :product_sweeper        def index          @products = product.all      end       def update_some_state       #... stuff doesn't trigger product save, invalidates cache     end end  

sweeper class:

class productsweeper < 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 called.     def after_update_some_state         expire_action(:controller => 'products', :action => 'index')      end end 

the activerecord callback 'after_save' work fine, callback on controller action 'after_update_some_state' never seems called.

looks missing controller name when trying callbacks controller actions working. sweeper should be:

class productsweeper < 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 called.     def after_products_update_some_state         expire_action(:controller => 'products', :action => 'index')      end      #can use before:     def before_products_update_some_state         #do before.      end end 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -