发新话题
打印

Shadowhand的page_cache_hook例子

Shadowhand的page_cache_hook例子

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 编辑 ]
本帖最近评分记录
  • Hex 威望 +2 感谢分享 2008-4-17 14:39

TOP

发新话题