
class ProductsController < 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 endend
清扫车类:
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 is called. def after_update_some_state expire_action(:controller => 'products',:action => 'index') endend ActiveRecord回调’after_save’将正常工作,但似乎永远不会调用控制器 *** 作’after_update_some_state’上的回调.
解决方法 在尝试获取控制器 *** 作的回调时,看起来我只是错过了控制器名称.我的清扫工应该是: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 is called. def after_products_update_some_state expire_action(:controller => 'products',:action => 'index') end #can also use before: def before_products_update_some_state #do something before. endend 总结 以上是内存溢出为你收集整理的ruby-on-rails – Rails Cache Sweeper全部内容,希望文章能够帮你解决ruby-on-rails – Rails Cache Sweeper所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)