Я пытаюсь реализовать Cache Sweeper, который будет фильтровать определенное действие контроллера.Rails Cache Sweeper
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
Sweeper Класс:
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' никогда, кажется, называется.
Итак, метод 'after_save' может использоваться вместо вызова' after_create' и 'after_update'? –