cachingwill-paginatepadrino

Caching pages with query strings in padrino-cache


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?


Solution

  • 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.