CodeIgniter Cache Control Technique For Browser

0
1687

CodeIgniter Cache Control Technique For Browser:
By default, web browsers do cache the results which our server generates.Here, we can tell the browser not to cache. Usually, we won’t want to prevent browser from caching except some special cases where our outputs are updated very often. So, instead of setting this commands as global/base controller, lets practice to use it only in the controllers/controller functions where it’s really needed. You can use the following code snippets only when you really want to prevent caching for browsers:
Cache on code
//cache on
/*$seconds_to_cache = 3600;
$ts = gmdate(“D, d M Y H:i:s”, time() + $seconds_to_cache) . ” GMT”;
header(“Expires: 2019:12:12 12:12 AM”);
header(“Pragma: cache”);
header(“Cache-Control: max-age=$seconds_to_cache”);*/

Cache off code
//cache clear
$this->output->set_header(“Cache-Control: no-store, no-cache, must-revalidate”);
$this->output->set_header(“Cache-Control: post-check=0, pre-check=0”);
$this->output->set_header(“Pragma: no-cache”);