示例#1
0
 /**
  * 析构时将本次请求所加载的类写入到文件缓存,下次预先加载
  */
 public function __destruct()
 {
     $path = $this->_reqPath();
     $key = $path . '::classes';
     $cache = Hi_Cache::factory('file');
     if (!$cache->exist($key)) {
         $cache->set($key, self::$_classes, 3600);
     }
 }
示例#2
0
 /**
  * 获取表的信息,相当于执行 desc table
  * 
  * @param $caseSensitive<bool> 字段名是否大小写敏感
  * @return array
  */
 public function info()
 {
     if (!empty($this->_info)) {
         return $this->_info;
     }
     $cacheKey = "db_table_info_{$this->_name}";
     $cache = Hi_Cache::factory();
     $info = $cache->get($cacheKey, true);
     if ($info) {
         $this->_info = $info;
         return $info;
     }
     $sql = "DESC {$this->_name}";
     try {
         $this->_info = $this->_db->fetchAssoc($sql, 'Field');
         $pks = array();
         foreach ($this->_info as $key => $val) {
             if ($val['Key'] == 'PRI') {
                 $pks[] = $key;
                 if ($val['Extra'] == 'auto_increment') {
                     $this->_isAutoIncrement = true;
                 }
             }
             if ($val['Key'] == 'UNI') {
                 $this->_uniqueKeys[] = $key;
             }
         }
         if (sizeof($pks) > 1) {
             throw new Hi_Db_Table_Exception('该类暂时还不支持联合主键的表');
         }
         $this->_primaryKey = $pks[0];
         if (isset($cache)) {
             $cache->set($cacheKey, $this->_info);
         }
         return $this->_info;
     } catch (Hi_Db_Exception $e) {
         throw new Hi_Db_Table_Exception($e->getMessage(), $e->getCode());
     }
 }
示例#3
0
 private function _setMcCache()
 {
     $this->_cache = Hi_Cache::factory('memcached');
 }
示例#4
0
 public function index()
 {
     echo 'Hello, world!';
     $cache = Hi_Cache::factory('file');
     echo $cache->get('xxxx');
 }