Welcome Guest, Not a member yet? Register   Sign In
Query String Support for Page Caching

Some of you may have run into this issue as I have, but currently if you have a page you'd like cached, but which uses a query string, then unfortunately you have to either disable caching, or enable query string support for all requests, which is either overkill, or potentially result in large numbers of junk cache files.

What I'd like to see is the ability to specify key variables that caching should use to distinguish pages. The simplest way would be to add an optional array to the cache() method. For example:

PHP Code:
class Foo extends CI_Controller {
function search() {
       $this->output->cache(15, ['q']);

       $results $this->some_model->get_results($this->input->get('q');
       $this->load->view('some/view', ['results' => $results]);

Here I've specified that the value of `q` should be used when loading/saving the cache-file, so now a cached file will only be used for this page if the value of `q` is a match. All other values are ignored as normal.

Alternatively a method might be preferable, as it could be used to additional parameters. For example, features similar to form validation could be useful to trim and lowercase the value of `q` if case and whitespace don't matter.

This is an issue that can crop up with some Javascript-based auto-complete controls, some of which don't allow you to send search requests in the form of search/foo, and there will be plenty of other cases as well.

So yeah, some means of telling the output library which values should also be considered, and optionally a means of filtering them automatically (rather than fiddling around with `$_GET`) would be great!

Now, I understand that the actual process of fetching the cache file will need some additions; my first thought is to add extra values to cached files, which can trigger a multi-step lookup if more details are required. As a result, pages that support query string based caching would have one default cache file to tell CodeIgniter what to do, and a set of actual cache files that can then potentially be used if there's a match.

Theme © iAndrew 2016 - Forum software by © MyBB