Skip to content

Instantly share code, notes, and snippets.

@John2496
Created June 15, 2010 20:51
Show Gist options
  • Save John2496/439714 to your computer and use it in GitHub Desktop.
Save John2496/439714 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Abstract controller class for automatic templating and view mapping.
*
* @package Controller
* @author John Himmelman (john2496@gmail.com)
*/
abstract class Controller_ViewMapper_Cache extends Controller_ViewMapper
{
public $use_cache = FALSE;
public $cache_id = '';
public $cache_lifetime = 60;
public function after()
{
$ret = NULL;
if ($this->use_cache)
{
$this->cache_id = $this->request->controller . '-' . $this->request->action;
$content = kohana::cache($this->cache_id);
if ($content)
{
$this->request->response = $content;
}
else
{
$ret = parent::after();
kohana::cache($this->cache_id, $this->request->response, $this->cache_lifetime);
}
}
else
{
$ret = parent::after();
}
return $ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment