소스 검색

DB 中增加cache 初始化功能

stanley-king 8 년 전
부모
커밋
d99e9c65fa
2개의 변경된 파일22개의 추가작업 그리고 26개의 파일을 삭제
  1. 6 9
      core/framework/function/core.php
  2. 16 17
      core/framework/libraries/model.php

+ 6 - 9
core/framework/function/core.php

@@ -436,27 +436,24 @@ function Model($model = null, $base_path = null)
 {
 {
 	static $_cache = array();
 	static $_cache = array();
 	$cache_key = $model.'.'.$base_path;
 	$cache_key = $model.'.'.$base_path;
-	if (!is_null($model) && isset($_cache[$cache_key])) {
+	if (!is_null($model) && isset($_cache[$cache_key]))
+	{
 		$ret = $_cache[$cache_key];
 		$ret = $_cache[$cache_key];
-		if (method_exists($ret,'has_cls')) {
-			if(!$ret->has_cls()) {
-				return $_cache[$cache_key];
-			}
-		} else {
-			return $_cache[$cache_key];
-		}		
+        $ret->init($model);
+		return $_cache[$cache_key];
     }
     }
 
 
 	$base_path = $base_path == null ? BASE_DATA_PATH : $base_path;
 	$base_path = $base_path == null ? BASE_DATA_PATH : $base_path;
 	$file_name = $base_path.'/model/'.$model.'.model.php';
 	$file_name = $base_path.'/model/'.$model.'.model.php';
 	$class_name = $model.'Model';
 	$class_name = $model.'Model';
+
 	if (!file_exists($file_name)){
 	if (!file_exists($file_name)){
 		return $_cache[$cache_key] =  new Model($model);
 		return $_cache[$cache_key] =  new Model($model);
 	}
 	}
     else
     else
     {
     {
 		require_once($file_name);
 		require_once($file_name);
-		if (!class_exists($class_name)){
+		if (!class_exists($class_name)) {
 			$error = 'Model Error:  Class '.$class_name.' is not exists!';
 			$error = 'Model Error:  Class '.$class_name.' is not exists!';
 			throw_exception($error);
 			throw_exception($error);
 		}else{
 		}else{

+ 16 - 17
core/framework/libraries/model.php

@@ -16,20 +16,27 @@ class Model
 	protected $db = null;
 	protected $db = null;
 	protected $fields = array();
 	protected $fields = array();
 	protected $unoptions = true;	//是否清空参数项,默认清除
 	protected $unoptions = true;	//是否清空参数项,默认清除
-    private $is_cls = false;
 
 
 	public function __construct($table = null)
 	public function __construct($table = null)
     {
     {
-		if (!is_null($table)){
-			$this->table_name = $table;
-			$this->tableInfo($table);
-		}
-		$this->table_prefix = DBPRE;
-		if (!is_object($this->db)){
-			$this->db = new ModelDb();
-		}
+        $this->table_prefix = DBPRE;
+        $this->init($table);
 	}
 	}
 
 
+	public function init($table)
+    {
+        $this->options = [];
+        $this->fields = [];
+
+        if (!is_null($table)){
+            $this->table_name = $table;
+            $this->tableInfo($table);
+        }
+
+        if (!is_object($this->db)){
+            $this->db = new ModelDb();
+        }
+    }
     /**
     /**
      * 删除表主键缓存
      * 删除表主键缓存
      */
      */
@@ -658,14 +665,9 @@ class Model
     public function cls(){
     public function cls(){
     	$this->options = array();
     	$this->options = array();
     	$this->table_name = '';
     	$this->table_name = '';
-        $this->is_cls = true;
     	return $this;
     	return $this;
     }
     }
 
 
-    public function has_cls() {
-        return $this->is_cls;
-    }
-
     public function checkActive($host = 'master') {
     public function checkActive($host = 'master') {
         $this->db->checkActive($host);
         $this->db->checkActive($host);
     }
     }
@@ -1191,9 +1193,6 @@ class ModelDb
     }
     }
 
 
     protected function parseDistinct($distinct) {
     protected function parseDistinct($distinct) {
-//        $ret = !empty($distinct)?   ' DISTINCT '.$distinct.',' :'';
-//        Log::record("parseDistinct ret = {$ret}",Log::DEBUG);
-//        return $ret;
         return !empty($distinct)?   ' DISTINCT '.$distinct.',' :'';
         return !empty($distinct)?   ' DISTINCT '.$distinct.',' :'';
     }
     }