We use Rails' caches_action
method along with Redis to implement caching of common pages.
It's a very dynamic site, so pages with differing URL params must remain distinct in the cache (e.g. ?page=1
vs ?page=2
). But as long as the URLs match, the content can be cached and served to multiple visitors.
Since a very high portion of our traffic comes from Adwords ads, many of our users were arriving at our pages with a gclid param in the URL, which rendered the caching useless. I worked around this by excluding the gclid from the cache path used to identify unique URLs:
caches_action :search,
:expires_in => 10.minutes,
:cache_path => Proc.new { |c| c.params.except('gclid') }
This worked great for a while, until I realized that our Analytics data was off because the HTML we were caching included internal links with the gclid param from previous visits.
So the solution to this is pretty straightforward- every time I generate a link I need to manually exclude gclid
, like:
link_to 'some page', params.except('gclid')
My question is: is there any way to automatically exclude gclid
from all generated links? It would be really handy to not have to do this manually throughout the site.
link_to
method by adding this line of yours. – MurifoX Apr 22 '13 at 14:28