Why should cache cleanings be declared on chips?

The cache utilizer is an observer with some hooks on the model he is observing:

class MySweeper < ActionController::Caching::Sweeper
  observe MyModel

  def after_update(my_model)
    expire_page(...)
  end
end

But the documentation and manuals also say to declare a sweeper in the controller:

class ApplicationController < ActionController::Base
  cache_sweeper :my_sweeper
end

Why is this? Does the observer point not observe the model and take no action? Should the controller not know when the cache expires or what causes it?

lightening

My understanding of setting up the sweeper as an observer is what it means "in all cases when MyModel is updated, run this cleanup code"

  • That's for sure?
  • If so, why cache_sweeper :my_sweeperalso need to be declared in the controller? What does it do?
+3
source share
1

:

.

, -, .

Sweeper , .. . , . , , - DB - .

, cache_sweeper , controller . , , .

class MySweeper < ActionController::Caching::Sweeper
  observe MyModel

  def after_update(my_model)
    expire_page(...)
  end

  def controller
    @controller ||= ActionController::Base.new
  end
end
+1

All Articles