用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3335|回复: 0
收起左侧

Shadowhand的page_cache_hook例子

[复制链接]
发表于 2008-4-17 13:16:29 | 显示全部楼层 |阅读模式
Shadowhand老大只放了个视频(http://kohanaphp.com/video/page_cache_hook.mov )没有贴代码,我把代码贴在这里,供大家参考
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);
 
复制代码

[ 本帖最后由 number5 于 2008-4-17 13:18 编辑 ]

评分

参与人数 1威望 +2 收起 理由
Hex + 2 感谢分享

查看全部评分

本版积分规则