Topic: Making Search Results Cacheable
I've deployed a vertical search site www.artsugar.com based on Rails. Its works fine, but some db queries take several seconds. Fortunately the search results are static for several weeks at a time and thus page caching seems like a good solution. Search parameters are submitted by the user in a form. Due to all the search parameters to the right of the ? in the url, standard rails page caching doesn't work without making some changes. I was hoping someone had an elegant way to enable page caching to work in this situation.
I've considered the following but it seems pretty nasty:
- setup a named route that puts the search query parameters between slashes instead of to the right of the ?
- let the user perform a query as today, but instead of the controller action running a search with the contents of params, it instead rewrites the search parameters into a pretty, cacheable url that matches the format of the named route and calls a redirect on this new pretty url
- a second controller action responds to the named route with the pretty url and actually performs the db query. Since the pretty url has no params to the right of the ?, its cacheable.
Hopefully there's a better way...