优化 table Cache
This commit is contained in:
parent
adba24ea28
commit
755f986844
|
@ -18,6 +18,8 @@ class discuz_table extends discuz_base
|
|||
public $data = array();
|
||||
|
||||
public $methods = array();
|
||||
|
||||
public $empty_ttl = 30;
|
||||
|
||||
protected $_table;
|
||||
protected $_pk;
|
||||
|
@ -92,7 +94,11 @@ class discuz_table extends discuz_base
|
|||
if(!empty($id)) {
|
||||
if($force_from_db || ($data = $this->fetch_cache($id)) === false) {
|
||||
$data = DB::fetch_first('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field($this->_pk, $id));
|
||||
if(!empty($data)) $this->store_cache($id, $data);
|
||||
if(!empty($data)) {
|
||||
$this->store_cache($id, $data);
|
||||
} else {
|
||||
$this->store_cache($id, array(), $this->empty_ttl);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
|
@ -113,6 +119,12 @@ class discuz_table extends discuz_base
|
|||
$this->store_cache($value[$this->_pk], $value);
|
||||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
|
|
|
@ -19,7 +19,8 @@ class table_forum_post extends discuz_table
|
|||
|
||||
$this->_table = 'forum_post';
|
||||
$this->_pk = 'pid';
|
||||
|
||||
$this->_pre_cache_key = 'forum_post_';
|
||||
$this->_cache_ttl = 0;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue