src/Core/Application.php
private function initRequestCache(array $request_cache_config, array $annotate_params)
    {
        if (empty($request_cache_config[0])) {
            return false;
        }

        if (!isset($request_cache_config[1]) || !is_array($request_cache_config[1])) {
            throw new CoreException('请求缓存配置格式不正确');
        }

        if (empty($request_cache_config[2]) && !$this->delegate->getRequest()->isGetRequest()) {
            return false;
        }

        $display_type = $this->config->get('sys', 'display');
        $this->delegate->getResponse()->setContentType($display_type);

        $default_cache_config = array(
            'type' => 1,
            'expire_time' => 3600,
            'ignore_params' => false,
            'cache_path' => $this->config->get('path', 'cache') . 'request' . DIRECTORY_SEPARATOR,
            'key_dot' => DIRECTORY_SEPARATOR
        );

        $cache_config = &$request_cache_config[1];
        foreach ($default_cache_config as $default_config_key => $default_value) {
            if (!isset($cache_config[$default_config_key])) {
                $cache_config[$default_config_key] = $default_value;
            }
        }

        $params_cache_key = '';
        $params = $this->getParams();
        if (!$cache_config['ignore_params'] && !empty($params)) {
            $params_member = &$params;
            if (!empty($annotate_params)) {
                foreach ($annotate_params as $k => &$v) {
                    if (isset($params[$k])) {
                        $v = $params[$k];
                    }
                }
                $params_member = $annotate_params;
            }

            $params_cache_key = md5(json_encode($params_member));
        }

        $cache_key = array(
            'app_name' => $this->app_name,
            'tpl_dir_name' => $this->config->get('sys', 'default_tpl_dir'),
            'controller' => lcfirst($this->getController()),
            'action' => $this->getAction()
        );

        $cache_config['key'] = implode($cache_config['key_dot'], $cache_key);
        if ($params_cache_key) {
            $cache_config['key'] .= '@' . $params_cache_key;
        }

        $closureContainer = $this->delegate->getClosureContainer();
        $has_cache_closure = $closureContainer->has('cpCache');
        if ($has_cache_closure) {
            $cache_config['params'] = $params;
            $cache_config['cache_key'] = $cache_key;
            $cache_config['annotate_params'] = $annotate_params;
            $enable_cache = $closureContainer->run('cpCache', array(&$cache_config));
            unset($cache_config['cache_key_config'], $cache_config['params'], $cache_config['annotate_params']);
        } else {
            $enable_cache = $request_cache_config[0];
        }

        if ($enable_cache) {
            return RequestCache::factory($cache_config['type'], $cache_config);
        }

        return false;
    }
private function initRequestCache(array $request_cache_config, array $annotate_params)
    {
        if (empty($request_cache_config[0])) {
            return false;
        }

        if (!isset($request_cache_config[1]) || !is_array($request_cache_config[1])) {
            throw new CoreException('请求缓存配置格式不正确');
        }

        if (empty($request_cache_config[2]) && !$this->delegate->getRequest()->isGetRequest()) {
            return false;
        }

        $display_type = $this->config->get('sys', 'display');
        $this->delegate->getResponse()->setContentType($display_type);

        $default_cache_config = array(
            'type' => 1,
            'expire_time' => 3600,
            'ignore_params' => false,
            'cache_path' => $this->config->get('path', 'cache') . 'request' . DIRECTORY_SEPARATOR,
            'key_dot' => DIRECTORY_SEPARATOR
        );

        $cache_config = &$request_cache_config[1];
        foreach ($default_cache_config as $default_config_key => $default_value) {
            if (!isset($cache_config[$default_config_key])) {
                $cache_config[$default_config_key] = $default_value;
            }
        }

        $params_cache_key = '';
        $params = $this->getParams();
        if (!$cache_config['ignore_params'] && !empty($params)) {
            $params_member = &$params;
            if (!empty($annotate_params)) {
                foreach ($annotate_params as $k => &$v) {
                    if (isset($params[$k])) {
                        $v = $params[$k];
                    }
                }
                $params_member = $annotate_params;
            }

            $params_cache_key = md5(json_encode($params_member));
        }

        $cache_key = array(
            'app_name' => $this->app_name,
            'tpl_dir_name' => $this->config->get('sys', 'default_tpl_dir'),
            'controller' => lcfirst($this->getController()),
            'action' => $this->getAction()
        );

        $cache_config['key'] = implode($cache_config['key_dot'], $cache_key);
        if ($params_cache_key) {
            $cache_config['key'] .= '@' . $params_cache_key;
        }

        $closureContainer = $this->delegate->getClosureContainer();
        $has_cache_closure = $closureContainer->has('cpCache');
        if ($has_cache_closure) {
            $cache_config['params'] = $params;
            $cache_config['cache_key'] = $cache_key;
            $cache_config['annotate_params'] = $annotate_params;
            $enable_cache = $closureContainer->run('cpCache', array(&$cache_config));
            unset($cache_config['cache_key_config'], $cache_config['params'], $cache_config['annotate_params']);
        } else {
            $enable_cache = $request_cache_config[0];
        }

        if ($enable_cache) {
            return RequestCache::factory($cache_config['type'], $cache_config);
        }

        return false;
    }
初始化请求缓存
<pre>
request_cache_config 共接受3个参数
1 缓存开关
2 缓存配置数组
3 是否强制开启请求缓存(忽略HTTP请求类型检查)

请求类型验证优先级大于缓存开关
注册匿名函数cpCache可以更灵活的控制请求缓存
</pre>

@param array $request_cache_config
@param array $annotate_params
@return bool|FileCacheDriver|Memcache|RedisCache|RequestCacheInterface|object
@throws CoreException