Shadowhand的page_cache_hook例子
Shadowhand老大只放了个视频(http://kohanaphp.com/video/page_cache_hook.mov )没有贴代码,我把代码贴在这里,供大家参考class hook_page_cache {
private $cache;
public function __construct()
{
$this->cache = new Cache();
Event::add_before('system.routing', array('Router', 'setup'),
array($this, 'load_cache'));
}
public function load_cache()
{
$uri = Router:current_uri;
if(empty($uri)) {
$uri = 'welcome';
}
if ($page = $this->cache->get('page_'. $uri))
{
Kohana::render($page);
exit();
}
else
{
Event::add('system.display', array($this, 'save_cache'));
}
}
public function save_cache()
{
$this->cache->set('page_'.Router::$current_uri, Event::$data);
}
}
$hook = new hook_page_cache();
unset($hook);
[ 本帖最后由 number5 于 2008-4-17 13:18 编辑 ]
页:
[1]