我刚刚尝试在加载 example.com/communities?sort=popular 时实现缓存
我的代码就是这样。但是,似乎缓存不起作用。
看起来它每次重新加载时仍在发送 SQL...
怎么了?然后当用户制作或编辑“社区”记录后,我想清除所有包含字符串“community_index_sort_by_”的存储缓存。
配置/环境/development.rb
...
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
config.cache_store = :dalli_store
...
community_controller.rb
def index
@key = "community_index_sort_by_" + params[:sort].to_s + "_page_" + params[:page].to_s
if params[:sort] == 'popular'
unless read_fragment(:controller => "communities", :action => "index", :action_suffix => @key)
@communities = Community.scoped.page(params[:page]).order("cached_votes_up DESC")
end
elsif params[:sort] == 'latest'
@communities = Community.scoped.page(params[:page]).order("created_at DESC")
end
end
我没碰过