I am working on a search application that uses a form with 16 filter options that are either 1 (selected) or 0 (not selected). The result as JSON is retrieved via AJAX using a GET request.
The query string then looks like this:
filter_1=0&filter_2=1 ...omitted... &filter_16=1&page=20
Each searchresult has at least 2 pages which can be browsed by the user.
My question is: how can I cache the searchresults based on the input parameter? My first idea was to md5 the requestparameters and then write a cache file using the hash as filename.
Every time a new request comes in, I search for the cache file and if it is there, then use the data from that file instead of querying the database and converting the rows to a json result.
But this seems not like a good idea because of the many search options. There would be quite a lot cache files (16 * 16 ???), and because the application is only used by a few users, I doubt that all possible combinations will ever get cached. And each result contains X pages, so each of that page would be a cache file of its own (16 * 16 * X).
What would be a good caching strategy for an application like this? Is it acutually possible to implement a cache?