/** * 设置数据缓存 * @access protected * @param mixed $data */ protected function _setDataCache($data, $saveFile = null) { if ($this->_data_cache_time > 0) { if (!$this->_cache_class instanceof XF_Cache_Interface) { throw new XF_Db_Table_Select_Exception('缓存器无法识别', 500); } if ($saveFile == null) { $saveFile = $this->_getDataCacheFileName(); } $this->_cache_class->setCacheTime($this->_data_cache_time)->add($saveFile, $data); } //设置临时缓存 XF_DataPool::getInstance()->addHash('TEMP_DATA_CACHE', md5($saveFile), $data); return true; }
/** * 渲染模板 * @access public * @param string $template_file Action模板文件 * @param string $cache_sign 缓存标识 * @param XF_View_Layout_Abstract $layout * @return string */ public function render($template_file = null, $cache_sign = '', XF_View_Layout_Abstract $layout = null) { $this->getTemplateStartLocation(); $request = XF_Controller_Request_Http::getInstance(); $appName = $request->getModule(); $controllerName = $request->getController(); $actionName = $request->getAction(); //如果没有设置模板,则自动获取当前Action名称相关的模板 if ($template_file == null) { $template_file = $this->_template_folder . '/' . $controllerName . '/' . $actionName . '.php'; } if (!is_file($template_file)) { throw new XF_View_Exception('Action template not found'); } $content = $this->obGetContents($template_file); XF_Controller_Plugin_Manage::getInstance()->postRender($content); //是否需要缓存? if ($this->_cache_time > 0) { $layout_tag = ''; if ($layout != null) { $layout_tag = '<!--Layout:' . get_class($layout) . ',' . $layout->getCacheTime() . ',' . (int) $layout->getCacheType() . '-->'; } $_content = $content . $layout_tag . $this->_makeCacheHeadTitleAndHeadMeta(); //写入缓存 if ($this->_cache_instance instanceof XF_Cache_SECache) { XF_File::mkdirs(TEMP_PATH . '/Cache'); $this->_cache_instance->setCacheSaveFile(TEMP_PATH . '/Cache/ActionViewCache'); } $this->_cache_instance->setCacheTime($this->_cache_time); $this->_cache_instance->add($cache_sign, $_content); } //是否启用布局 if ($layout != null) { $layout->assign('$layoutContent', $content); $content = $layout->render(); } return $content; }