优化 Cache
This commit is contained in:
parent
755f986844
commit
e99b4efb64
|
@ -87,6 +87,9 @@ $_config['db']['common']['slave_except_table'] = '';
|
|||
* 当 memcache 无法启用时,会自动开启另外的两种优化模式
|
||||
*/
|
||||
|
||||
//空值缓存有效期,默认30秒
|
||||
$_config['cache']['empty_ttl'] = 30;
|
||||
|
||||
//内存变量前缀, 可更改,避免同服务器中的程序引用错乱
|
||||
$_config['memory']['prefix'] = 'discuz_';
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ class discuz_table extends discuz_base
|
|||
|
||||
public $methods = array();
|
||||
|
||||
public $empty_ttl = 30;
|
||||
|
||||
protected $_empty_ttl;
|
||||
protected $_table;
|
||||
protected $_pk;
|
||||
protected $_pre_cache_key;
|
||||
|
@ -31,6 +30,12 @@ class discuz_table extends discuz_base
|
|||
if(!empty($para)) {
|
||||
$this->_table = $para['table'];
|
||||
$this->_pk = $para['pk'];
|
||||
}
|
||||
if(!isset($this->_empty_ttl) && ($empty_ttl = getglobal('config/cache/empty_ttl'))) {
|
||||
$this->_empty_ttl = $empty_ttl;
|
||||
}
|
||||
if(empty($this->_empty_ttl)) {
|
||||
$this->_empty_ttl = 30;
|
||||
}
|
||||
if(isset($this->_pre_cache_key) && (($ttl = getglobal('setting/memory/'.$this->_table)) !== null || ($ttl = $this->_cache_ttl) !== null) && memory('check')) {
|
||||
$this->_cache_ttl = $ttl;
|
||||
|
@ -89,7 +94,7 @@ class discuz_table extends discuz_base
|
|||
}
|
||||
}
|
||||
|
||||
public function fetch($id, $force_from_db = false){
|
||||
public function fetch($id, $force_from_db = false){
|
||||
$data = array();
|
||||
if(!empty($id)) {
|
||||
if($force_from_db || ($data = $this->fetch_cache($id)) === false) {
|
||||
|
@ -97,7 +102,7 @@ class discuz_table extends discuz_base
|
|||
if(!empty($data)) {
|
||||
$this->store_cache($id, $data);
|
||||
} else {
|
||||
$this->store_cache($id, array(), $this->empty_ttl);
|
||||
$this->store_cache($id, array(), $this->_empty_ttl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +127,7 @@ class discuz_table extends discuz_base
|
|||
$diff_ids = array_diff($ids, array_keys($data));
|
||||
if(!empty($diff_ids)) {
|
||||
foreach($diff_ids as $diff_id) {
|
||||
$this->store_cache($diff_id, array(), $this->empty_ttl);
|
||||
$this->store_cache($diff_id, array(), $this->_empty_ttl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue