[code]
# javascripts_controller.rb
caches_page :dynamic_states
# config/environments/development.rb
config.action_controller.perform_caching = true
# config/environment.rb
config.load_paths << "#{RAILS_ROOT}/app/sweepers"
# app/sweepers/state_sweeper.rb
class StateSweeper < ActionController::Caching::Sweeper
observe State
def after_save(state)
expire_cache(state)
end
def after_destroy(state)
expire_cache(state)
end
def expire_cache(state)
expire_page :controller => 'javascripts', :action => 'dynamic_states', :format => 'js'
end
end
# states_controller.rb
cache_sweeper :state_sweeper, :only => [:create, :update, :destroy]
[/code]
越来越觉得看RailsCast没收货了,讲的太小儿科,学不到什么东西,内容又比较火星
关于Cache,[url=http://hideto.iteye.com/blog/87588]Rails Cache[/url]这篇讲的更全面更深入
今天用t61外接公司的显示器,双显示器来用,结果经常在台式的键盘上敲半天还奇怪为什么没反应。。。
# javascripts_controller.rb
caches_page :dynamic_states
# config/environments/development.rb
config.action_controller.perform_caching = true
# config/environment.rb
config.load_paths << "#{RAILS_ROOT}/app/sweepers"
# app/sweepers/state_sweeper.rb
class StateSweeper < ActionController::Caching::Sweeper
observe State
def after_save(state)
expire_cache(state)
end
def after_destroy(state)
expire_cache(state)
end
def expire_cache(state)
expire_page :controller => 'javascripts', :action => 'dynamic_states', :format => 'js'
end
end
# states_controller.rb
cache_sweeper :state_sweeper, :only => [:create, :update, :destroy]
[/code]
越来越觉得看RailsCast没收货了,讲的太小儿科,学不到什么东西,内容又比较火星
关于Cache,[url=http://hideto.iteye.com/blog/87588]Rails Cache[/url]这篇讲的更全面更深入
今天用t61外接公司的显示器,双显示器来用,结果经常在台式的键盘上敲半天还奇怪为什么没反应。。。
本文通过具体的Rails代码示例展示了如何使用Rails中的缓存机制,包括配置缓存、定义缓存清理器以及针对特定控制器动作的缓存更新策略。
3266

被折叠的 条评论
为什么被折叠?



