From 2140a5dec248b9df4763d725f3a5c9f211a803dc Mon Sep 17 00:00:00 2001 From: luofei614 Date: Thu, 12 Sep 2013 11:20:05 +0800 Subject: [PATCH] =?UTF-8?q?Storage=20=E5=A2=9E=E5=8A=A0type=20=EF=BC=8C?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E4=B8=8D=E5=90=8C=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Common/functions.php | 10 +++++----- ThinkPHP/Conf/convention.php | 2 +- ThinkPHP/Library/Think/Action.class.php | 4 ++-- .../Behavior/ParseTemplateBehavior.class.php | 14 +++++++------- .../Behavior/ReadHtmlCacheBehavior.class.php | 8 ++++---- .../Behavior/WriteHtmlCacheBehavior.class.php | 4 ++-- .../Think/Storage/Driver/File.class.php | 18 +++++++++--------- ThinkPHP/Library/Think/Template.class.php | 4 ++-- ThinkPHP/Library/Think/Think.class.php | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/ThinkPHP/Common/functions.php b/ThinkPHP/Common/functions.php index 923ac3f..0f85ef4 100644 --- a/ThinkPHP/Common/functions.php +++ b/ThinkPHP/Common/functions.php @@ -338,10 +338,10 @@ function F($name, $value='', $path=DATA_PATH) { if(false !== strpos($name,'*')){ return false; // TODO }else{ - return Think\Storage::unlink($filename); + return Think\Storage::unlink($filename,'F'); } } else { - Think\Storage::put($filename,serialize($value)); + Think\Storage::put($filename,serialize($value),'F'); // 缓存数据 $_cache[$name] = $value; return ; @@ -350,8 +350,8 @@ function F($name, $value='', $path=DATA_PATH) { // 获取缓存数据 if (isset($_cache[$name])) return $_cache[$name]; - if (Think\Storage::has($filename)){ - $value = unserialize(Think\Storage::read($filename)); + if (Think\Storage::has($filename,'F')){ + $value = unserialize(Think\Storage::read($filename,'F')); $_cache[$name] = $value; } else { $value = false; @@ -666,4 +666,4 @@ function filter_exp(&$value){ if (in_array(strtolower($value),array('exp','or'))){ $value .= ' '; } -} \ No newline at end of file +} diff --git a/ThinkPHP/Conf/convention.php b/ThinkPHP/Conf/convention.php index 5b76baa..0572c82 100644 --- a/ThinkPHP/Conf/convention.php +++ b/ThinkPHP/Conf/convention.php @@ -141,4 +141,4 @@ return array( 'OUTPUT_ENCODE' => false, // 页面压缩输出 'HTTP_CACHE_CONTROL' => 'private', // 网页缓存控制 -); \ No newline at end of file +); diff --git a/ThinkPHP/Library/Think/Action.class.php b/ThinkPHP/Library/Think/Action.class.php index 3ed8f8e..98a93ea 100644 --- a/ThinkPHP/Library/Think/Action.class.php +++ b/ThinkPHP/Library/Think/Action.class.php @@ -107,7 +107,7 @@ abstract class Action { $content = $this->fetch($templateFile); $htmlpath = !empty($htmlpath)?$htmlpath:HTML_PATH; $htmlfile = $htmlpath.$htmlfile.C('HTML_FILE_SUFFIX'); - Storage::put($htmlfile , $content); + Storage::put($htmlfile , $content,'html'); return $content; } @@ -312,4 +312,4 @@ abstract class Action { // 执行后续操作 tag('action_end'); } -} \ No newline at end of file +} diff --git a/ThinkPHP/Library/Think/Behavior/ParseTemplateBehavior.class.php b/ThinkPHP/Library/Think/Behavior/ParseTemplateBehavior.class.php index 885ae69..ac1dc57 100644 --- a/ThinkPHP/Library/Think/Behavior/ParseTemplateBehavior.class.php +++ b/ThinkPHP/Library/Think/Behavior/ParseTemplateBehavior.class.php @@ -58,7 +58,7 @@ class ParseTemplateBehavior extends Behavior { // 分解变量并载入模板缓存 extract($_data['var'], EXTR_OVERWRITE); //载入模版缓存文件 - include C('CACHE_PATH').$_data['prefix'].md5($_content).C('TMPL_CACHFILE_SUFFIX'); + Storage::load(C('CACHE_PATH').$_data['prefix'].md5($_content).C('TMPL_CACHFILE_SUFFIX'),'tpl'); }else{ $tpl = Think::instance('Think\\Template'); // 编译并加载模板文件 @@ -87,19 +87,19 @@ class ParseTemplateBehavior extends Behavior { if (!C('TMPL_CACHE_ON')) // 优先对配置设定检测 return false; $tmplCacheFile = C('CACHE_PATH').$prefix.md5($tmplTemplateFile).C('TMPL_CACHFILE_SUFFIX'); - if(!Storage::has($tmplCacheFile)){ + if(!Storage::has($tmplCacheFile,'tpl')){ return false; - }elseif (filemtime($tmplTemplateFile) > Storage::get($tmplCacheFile,'mtime')) { + }elseif (filemtime($tmplTemplateFile) > Storage::get($tmplCacheFile,'mtime','tpl')) { // 模板文件如果有更新则缓存需要更新 return false; - }elseif (C('TMPL_CACHE_TIME') != 0 && time() > Storage::get($tmplCacheFile,'mtime')+C('TMPL_CACHE_TIME')) { + }elseif (C('TMPL_CACHE_TIME') != 0 && time() > Storage::get($tmplCacheFile,'mtime','tpl')+C('TMPL_CACHE_TIME')) { // 缓存是否在有效期 return false; } // 开启布局模板 if(C('LAYOUT_ON')) { $layoutFile = THEME_PATH.C('LAYOUT_NAME').C('TMPL_TEMPLATE_SUFFIX'); - if(filemtime($layoutFile) > Storage::get($tmplCacheFile,'mtime')) { + if(filemtime($layoutFile) > Storage::get($tmplCacheFile,'mtime','tpl')) { return false; } } @@ -115,10 +115,10 @@ class ParseTemplateBehavior extends Behavior { * @return boolean */ protected function checkContentCache($tmplContent,$prefix='') { - if(Storage::has(C('CACHE_PATH').$prefix.md5($tmplContent).C('TMPL_CACHFILE_SUFFIX'))){ + if(Storage::has(C('CACHE_PATH').$prefix.md5($tmplContent).C('TMPL_CACHFILE_SUFFIX'),'tpl')){ return true; }else{ return false; } } -} \ No newline at end of file +} diff --git a/ThinkPHP/Library/Think/Behavior/ReadHtmlCacheBehavior.class.php b/ThinkPHP/Library/Think/Behavior/ReadHtmlCacheBehavior.class.php index 6ce5ff5..56aff69 100644 --- a/ThinkPHP/Library/Think/Behavior/ReadHtmlCacheBehavior.class.php +++ b/ThinkPHP/Library/Think/Behavior/ReadHtmlCacheBehavior.class.php @@ -34,7 +34,7 @@ class ReadHtmlCacheBehavior extends Behavior { $cacheTime = $this->requireHtmlCache(); if( false !== $cacheTime && $this->checkHTMLCache(HTML_FILE_NAME,$cacheTime)) { //静态页面有效 // 读取静态页面输出 - echo Storage::read(HTML_FILE_NAME); + echo Storage::read(HTML_FILE_NAME,'html'); exit(); } } @@ -112,12 +112,12 @@ class ReadHtmlCacheBehavior extends Behavior { static public function checkHTMLCache($cacheFile='',$cacheTime='') { if(!is_file($cacheFile)){ return false; - }elseif (filemtime(C('TEMPLATE_NAME')) > Storage::get($cacheFile,'mtime')) { + }elseif (filemtime(C('TEMPLATE_NAME')) > Storage::get($cacheFile,'mtime','html')) { // 模板文件如果更新静态文件需要更新 return false; }elseif(!is_numeric($cacheTime) && function_exists($cacheTime)){ return $cacheTime($cacheFile); - }elseif ($cacheTime != 0 && NOW_TIME > Storage::get($cacheFile,'mtime')+$cacheTime) { + }elseif ($cacheTime != 0 && NOW_TIME > Storage::get($cacheFile,'mtime','html')+$cacheTime) { // 文件是否在有效期 return false; } @@ -132,4 +132,4 @@ class ReadHtmlCacheBehavior extends Behavior { return !method_exists($class,$action); } -} \ No newline at end of file +} diff --git a/ThinkPHP/Library/Think/Behavior/WriteHtmlCacheBehavior.class.php b/ThinkPHP/Library/Think/Behavior/WriteHtmlCacheBehavior.class.php index 45b8563..221fa41 100644 --- a/ThinkPHP/Library/Think/Behavior/WriteHtmlCacheBehavior.class.php +++ b/ThinkPHP/Library/Think/Behavior/WriteHtmlCacheBehavior.class.php @@ -25,7 +25,7 @@ class WriteHtmlCacheBehavior extends Behavior { public function run(&$content){ if(C('HTML_CACHE_ON') && defined('HTML_FILE_NAME')) { //静态文件写入 - Storage::put(HTML_FILE_NAME , $content); + Storage::put(HTML_FILE_NAME , $content,'html'); } } -} \ No newline at end of file +} diff --git a/ThinkPHP/Library/Think/Storage/Driver/File.class.php b/ThinkPHP/Library/Think/Storage/Driver/File.class.php index 0814144..a9e7376 100644 --- a/ThinkPHP/Library/Think/Storage/Driver/File.class.php +++ b/ThinkPHP/Library/Think/Storage/Driver/File.class.php @@ -26,7 +26,7 @@ class File extends Storage{ * @param string $filename 文件名 * @return string */ - public function read($filename){ + public function read($filename,$type=''){ return $this->get($filename,'content'); } @@ -37,7 +37,7 @@ class File extends Storage{ * @param string $content 文件内容 * @return boolean */ - public function put($filename,$content){ + public function put($filename,$content,$type=''){ $dir = dirname($filename); if(!is_dir($dir)) mkdir($dir,0755,true); @@ -55,11 +55,11 @@ class File extends Storage{ * @param string $content 追加的文件内容 * @return boolean */ - public function append($filename,$content){ + public function append($filename,$content,$type=''){ if(is_file($filename)){ $content = $this->read($filename).$content; } - return $this->put($filename,$content); + return $this->put($filename,$content,$type); } /** @@ -69,7 +69,7 @@ class File extends Storage{ * @param array $vars 传入变量 * @return void */ - public function load($filename,$vars=null){ + public function load($filename,$vars=null,$type=''){ if(!is_null($vars)) extract($vars, EXTR_OVERWRITE); include $filename; @@ -81,7 +81,7 @@ class File extends Storage{ * @param string $filename 文件名 * @return boolean */ - public function has($filename){ + public function has($filename,$type=''){ return file_exists($filename); } @@ -91,7 +91,7 @@ class File extends Storage{ * @param string $filename 文件名 * @return boolean */ - public function unlink($filename){ + public function unlink($filename,$type=''){ return unlink($filename); } @@ -102,7 +102,7 @@ class File extends Storage{ * @param string $name 信息名 mtime或者content * @return boolean */ - public function get($filename,$name){ + public function get($filename,$name,$type=''){ if(!is_file($filename)) return false; $content= file_get_contents($filename); $info = array( @@ -111,4 +111,4 @@ class File extends Storage{ ); return $info[$name]; } -} \ No newline at end of file +} diff --git a/ThinkPHP/Library/Think/Template.class.php b/ThinkPHP/Library/Think/Template.class.php index 7d20c8a..ba48a8a 100644 --- a/ThinkPHP/Library/Think/Template.class.php +++ b/ThinkPHP/Library/Think/Template.class.php @@ -78,7 +78,7 @@ class Template { public function fetch($templateFile,$templateVar,$prefix='') { $this->tVar = $templateVar; $templateCacheFile = $this->loadTemplate($templateFile,$prefix); - Storage::load($templateCacheFile,$this->tVar); + Storage::load($templateCacheFile,$this->tVar,'tpl'); } /** @@ -111,7 +111,7 @@ class Template { } // 编译模板内容 $tmplContent = $this->compiler($tmplContent); - Storage::put($tmplCacheFile,trim($tmplContent)); + Storage::put($tmplCacheFile,trim($tmplContent),'tpl'); return $tmplCacheFile; } diff --git a/ThinkPHP/Library/Think/Think.class.php b/ThinkPHP/Library/Think/Think.class.php index f52fe68..3dbb5f2 100644 --- a/ThinkPHP/Library/Think/Think.class.php +++ b/ThinkPHP/Library/Think/Think.class.php @@ -271,4 +271,4 @@ class Think { include C('TMPL_EXCEPTION_FILE'); exit; } -} \ No newline at end of file +} -- Gitee