Skip to content

Instantly share code, notes, and snippets.

@haliphax
Created May 9, 2013 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save haliphax/5545491 to your computer and use it in GitHub Desktop.
Save haliphax/5545491 to your computer and use it in GitHub Desktop.
Browsercache.php - A simple browser-cache-handling library for CodeIgniter

Browsercache.php

Throw it in your application/libraries folder, and use it like so:

  • To cache a page for 30 minutes: $this->browsercache->cacheFor(30);
  • To prevent a page from being cached: $this->browsercache->dontCache();

Yup. That's it.

<?php if(! defined('BASEPATH')) exit();
class Browsercache
{
private $ci;
function __construct()
{
$this->ci =& get_instance();
}
public function cacheFor($minutes)
{
$this->ci->output->cache($minutes);
$this->ci->output->set_header('Expires: ' . gmdate('D, d M Y H:i:s', time() + ($minutes * 60)) . ' GMT');
}
public function dontCache()
{
$this->ci->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->ci->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
$this->ci->output->set_header("Pragma: no-cache");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment