From bc1e918af3ed9383b6dc233e2e6a80bd960d2a27 Mon Sep 17 00:00:00 2001 From: liugang Date: Thu, 31 Oct 2024 17:02:06 +0800 Subject: [PATCH] + [refac] add method to load cache. --- framework/base/router.class.php | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/framework/base/router.class.php b/framework/base/router.class.php index 742fab944f..78e7d41ece 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -306,6 +306,15 @@ class baseRouter */ public $lang; + /** + * 全局缓存对象,用于操作缓存。 + * The global cache object, used to operate cache. + * + * @var object + * @access public + */ + public $cache = null; + /** * 全局$dbh对象,数据库连接句柄。 * The global $dbh object, the database connection handler. @@ -494,12 +503,7 @@ class baseRouter $this->setTimezone(); if($this->config->framework->autoConnectDB) $this->connectDB(); - - if($this->config->redis->enable) - { - $this->loadClass('zredis', true); - $this->redis = new zredis($this); - } + if($this->config->cache->enable) $this->loadCache(); $this->setupProfiling(); $this->setupXhprof(); @@ -3080,6 +3084,23 @@ class baseRouter $this->mao = new mao($this); } + /** + * 加载缓存类,初始化全局缓存对象。 + * Load the cache class and init the global cache object. + * + * @access public + * @return void + */ + private function loadCache() + { + $this->loadClass('cache', true); + $this->cache = new cache($this); + + /* 为 dao 和 mao 设置访问缓存的对象。 Set the cache object for dao and mao. */ + $this->dao->cache = $this->cache; + $this->mao->cache = $this->cache; + } + /** * Init config of slave db. *