Module Cache Sweeping

在项目的app下新建目录sweeper,在该目录下新建sweeper类的文件,如listen_sweeper.rb class

 

class ListenSweeper < ActionController::Caching::Sweeper
  observer User, Production #observer Model you wanted
  
  def after_save(record)
  end
  
  def after_update(record)
  end
  
  def after_destroy(record)
  end
  
  private

  def do_something
    expire_page(:controller => "lists", :action => %w( show public feed ), :id => list.id)
    expire_action(:controller => "lists", :action => "all")
  end
end
 

 

在相应的controller中,

 

cache_sweeper :listen_sweeper, :only => [:action_one, :action_two]
 

需要在config/application.rb中加载

 

config.autoload_paths += %W(#{Rails.root}/app/sweepers)

你可能感兴趣的:(cache,Rails)