Exemplo n.º 1
0
 /**
  * 设置数据缓存
  * @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;
 }
Exemplo n.º 2
0
 /**
  * 检测是否存在缓存文件
  * @access private
  * @return void
  */
 private function _checkCacheContent()
 {
     $key = $this->getCacheSign();
     if ($key == '') {
         return;
     }
     //如果没有设置缓存类型,则默认为secache
     if ($this->_cache_instance == null) {
         $this->_cache_instance = XF_Cache_SECache::getInstance();
     }
     if ($this->_cache_instance instanceof XF_Cache_SECache) {
         $cache_file = TEMP_PATH . '/Cache/ActionViewCache';
         if (!is_file($cache_file . '.php')) {
             return null;
         }
         $this->_cache_instance->setCacheSaveFile($cache_file);
     }
     //是否存强制清除缓存
     if (XF_DataPool::getInstance()->get('clearActionCache') === true) {
         $this->_cache_instance->remove($key);
         return null;
     }
     $content = $this->_cache_instance->read($key);
     if ($content == XF_CACHE_EMPTY) {
         return null;
     }
     //检测布局
     preg_match('/<!--Layout:(.*?)-->/', $content, $matches);
     if (isset($matches[0])) {
         $tmp = explode(',', $matches[1]);
         $layoutName = $tmp[0];
         $layout = new $layoutName();
         $layout->setCacheTime($tmp[1]);
         $layout->setCacheType($tmp[2]);
         //清除布局标记
         $content = str_replace($matches[0], '', $content);
         //执行布局对象,并渲染布局模板
         if ($layout instanceof XF_View_Layout_Abstract) {
             //获取缓存的标题等信息
             $this->_checkCacheHtmlTag($content);
             $layout->assign('$layoutContent', $content);
             $content = $layout->render();
         }
     }
     return $content;
 }
Exemplo n.º 3
0
Arquivo: View.php Projeto: kevinwan/xf
 /**
  * 渲染模板
  * @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;
 }