如何在Rails中缓存带有查询字符串参数的REST控制器?
Example: GET /products/all.xml?max_price=200
谢谢!
如何在Rails中缓存带有查询字符串参数的REST控制器?
Example: GET /products/all.xml?max_price=200
谢谢!
如果您想基于所有查询参数(或者几乎全部)对某个操作进行缓存,您可以执行以下操作:
caches_action :my_action, :cache_path => Proc.new { |c| c.params }
或者,也许你想获取除了一些仅用于分析(但对你正在获取的记录没有影响)的参数之外的所有参数:
caches_action :my_action, :cache_path => Proc.new { |c| c.params.delete_if { |k,v| k.starts_with?('utm_') } }
caches_action :index, :cache_path => Proc.new {|c| c.request.url }
cache(params[:max_price], :expires_in => 10.minute) do
# get the result
end