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

[讨论/交流] core->Output.php->_display_cache 函数疑问

[复制链接]
发表于 2011-9-2 10:08:17 | 显示全部楼层 |阅读模式
PHP复制代码
 
/**
     * Update/serve a cached file
     *
     * @access    public
     * @return    void
     */

    function _display_cache(&$CFG, &$URI)
    {
        $cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');
 
        // Build the file path.  The file name is an MD5 hash of the full URI
        $uri =    $CFG->item('base_url').
                $CFG->item('index_page').
                $URI->uri_string;
 
        $filepath = $cache_path.md5($uri);
 
        if ( ! @file_exists($filepath))
        {
            return FALSE;
        }
 
        if ( ! $fp = @fopen($filepath, FOPEN_READ))
        {
            return FALSE;
        }
 
        flock($fp, LOCK_SH);
 
        $cache = '';
        if (filesize($filepath) > 0)
        {
            $cache = fread($fp, filesize($filepath));
        }
 
        flock($fp, LOCK_UN);
        fclose($fp);
 
        // Strip out the embedded timestamp
        if ( ! preg_match("/(\d+TS--->)/", $cache, $match))
        {
            return FALSE;
        }
 
        // Has the file expired? If so we'll delete it.
        if (time() >= trim(str_replace('TS--->', '', $match['1'])))
        {
            if (is_really_writable($cache_path))
            {
                @unlink($filepath);
                log_message('debug', "Cache file has expired. File deleted");
                return FALSE;
            }
        }
 
        // Display the cache
        $this->_display(str_replace($match['0'], '', $cache));
        log_message('debug', "Cache file is current. Sending it to browser.");
        return TRUE;
    }
 
复制代码


当缓存文件过期时 为何不重新解析文件呢? 而是返回false

发表于 2011-9-2 10:39:47 | 显示全部楼层
返回了,就去执行控制器了,在那之后会重建缓存
 楼主| 发表于 2011-9-2 10:56:54 | 显示全部楼层
jeongee 发表于 2011-9-2 10:39
返回了,就去执行控制器了,在那之后会重建缓存

_display_cache()中有调用_display()  应该是在最后执行的吧 ;

本版积分规则