Caching pages with query strings in padrino-cache

65 Views Asked by At

I have Padrino caching working in my app, e.g.

get :blog, cache: true do
# do a blog listing
end

But when the listings are paginated with will-paginate, it can't tell the difference between /blog and /blog?page=2, and always renders the cached copy of /blog. Is there any way to get this to work so that it caches per URL not per route?

1

There are 1 best solutions below

0
On BEST ANSWER

Some spelunking in the Padrino issues provides this answer, which seems to work:

get :blog, cache: Padrino.config.cache do
  cache_key { request.path_info + '?' + params.slice('page').to_param }
  #do blog listing
end

The structure of the Padrino documentation seems to have changed since then, so the PR at the end of that issue no longer seems to be in the current documentation.