How can I cache my REST controller with Rails where my actions have query string parameters?
Example: GET /products/all.xml?max_price=200
Thx!
How can I cache my REST controller with Rails where my actions have query string parameters?
Example: GET /products/all.xml?max_price=200
Thx!
if you want to cache on client side, here are some useful links:
just send the proper HTTP headers and the client will cache the response
In this case you should use fragments caching:
in your controller:
cache(params[:max_price], :expires_in => 10.minute) do
# get the result
end
I just blogged about this (see that for longer explanation), but if you want to cache an action, based on all the query parameters (or say on nearly all of them), you can do:
caches_action :my_action, :cache_path => Proc.new { |c| c.params }
Or, maybe you want all but some params that you just use for Analytics (but that have no bearing on the records you're fetching):
caches_action :my_action, :cache_path => Proc.new { |c| c.params.delete_if { |k,v| k.starts_with?('utm_') } }
To use the request url as cache key I do something like this:
caches_action :index, :cache_path => Proc.new {|c| c.request.url }