【发布时间】:2011-04-15 19:55:44
【问题描述】:
我正在尝试实现一个缓存清扫器,它会过滤特定的控制器操作。
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
end
end
清扫班:
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')
end
end
ActiveRecord 回调“after_save”可以正常工作,但控制器操作“after_update_some_state”的回调似乎永远不会被调用。
【问题讨论】:
标签: ruby-on-rails caching