CodeIgniter 中国开发者社区诚征热爱 CI 的版主

查看完整版本: Shadowhand的page_cache_hook例子

number5 2008-4-17 13:16

Shadowhand的page_cache_hook例子

Shadowhand老大只放了个视频([url]http://kohanaphp.com/video/page_cache_hook.mov[/url] )没有贴代码,我把代码贴在这里,供大家参考
[code=PHP]
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);
[/code]

[[i] 本帖最后由 number5 于 2008-4-17 13:18 编辑 [/i]]
页: [1]
查看完整版本: Shadowhand的page_cache_hook例子