Codeigniter caching issue when dealing with query string parameters Codeigniter caching issue when dealing with query string parameters codeigniter codeigniter

Codeigniter caching issue when dealing with query string parameters


this can fix codeigniter cache with querystringcodeigniter cache with querystring

it is thai language page but you can just copy that code and put it in application/core/MY_Output.php :)


Into config/config.php

You should enable cache_query_string like this

$config['cache_query_string'] = TRUE;

take all query parameters into account.Please be aware that this may result in numerous cache files generated for the same page over and over again.


Here's some code to override Codeigniter's Output class which seems to work for me.

Create the file application/core/MY_Output.php, copy in the _write_cache() and _display_cache() functions from Output.php and update it like this:

class MY_Output extends CI_Output {    function __construct() {        parent::__construct();    }    function _write_cache($output) {        ....        $uri = $CI->config->item('base_url').               $CI->config->item('index_page').               $CI->uri->uri_string();        // append querystring        $qs = (empty($_SERVER['QUERY_STRING'])) ? '' : '?'.$_SERVER['QUERY_STRING'];        $uri .= $qs;        // append querystring          ....    }    function _display_cache(&$CFG, &$URI)        ....        $uri = $CI->config->item('base_url').               $CI->config->item('index_page').               $URI->uri_string;        // append querystring        $qs = (empty($_SERVER['QUERY_STRING'])) ? '' : '?'.$_SERVER['QUERY_STRING'];        $uri .= $qs;        // append querystring        ....    }