`
cinic2003
  • 浏览: 37096 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics