• R/O
  • SSH
  • HTTPS

jinrousiki: Commit


Commit MetaInfo

Revisão2342 (tree)
Hora2019-10-08 01:31:24
Autorumethyl

Mensagem de Log

JinrouCache:プロパティを最適化

Mudança Sumário

Diff

--- trunk/include/cache_class.php (revision 2341)
+++ trunk/include/cache_class.php (revision 2342)
@@ -8,7 +8,7 @@
88 const LOG_LIST = 'old_log_list';
99
1010 //クラスのロード
11- static function Load($name = null, $expire = null) {
11+ static function Load($name = null, $expire = 0) {
1212 static $instance;
1313
1414 if (is_null($instance)) {
@@ -103,7 +103,9 @@
103103 //保存情報取得
104104 public static function Fetch($serialize = false) {
105105 $data = JinrouCacheDB::Get();
106- if (self::Expire($data)) return null;
106+ if (self::Expire($data)) {
107+ return null;
108+ }
107109
108110 self::Load()->updated = true;
109111 self::Load()->next = $data['expire'];
@@ -129,7 +131,9 @@
129131
130132 //保存処理
131133 public static function Store($object, $serialize = false, $force = false) {
132- if (false === $force && self::Load()->updated) return;
134+ if (false === $force && self::Load()->updated) {
135+ return true;
136+ }
133137
134138 $content = gzdeflate($serialize ? serialize($object) : $object);
135139 if (JinrouCacheDB::Exists()) { //存在するならロックする
@@ -169,7 +173,9 @@
169173
170174 //有効期限切れ判定
171175 private static function Expire($data) {
172- if (is_null($data) || Time::Get() > $data['expire']) return true;
176+ if (is_null($data) || Time::Get() > $data['expire']) {
177+ return true;
178+ }
173179 return isset(self::Load()->hash) && isset($data['hash']) && self::Load()->hash != $data['hash'];
174180 }
175181 }
@@ -178,20 +184,21 @@
178184 final class JinrouCache {
179185 public $room_no = 0;
180186 public $name = null;
187+ public $now = null;
181188 public $expire = 0;
189+ public $next = null;
182190 public $hash = null;
183191 public $updated = false; //更新済み判定
184- public $next = null;
185192
186193 //クラスの初期化
187194 public function __construct($name, $expire = 0) {
188195 $this->room_no = DB::ExistsRoom() ? DB::$ROOM->id : 0;
189196 $this->name = $name;
197+ $this->now = Time::Get();
190198 $this->expire = $expire;
199+ $this->next = $this->now + $this->expire;
191200 if (DB::ExistsRoom() && DB::ExistsUser()) {
192201 $this->hash = md5(DB::$ROOM->scene . DB::$USER->Count());
193- } else {
194- $this->hash = null;
195202 }
196203 }
197204
--- trunk/include/database/cache_db_class.php (revision 2341)
+++ trunk/include/database/cache_db_class.php (revision 2342)
@@ -25,16 +25,13 @@
2525 ->Into(['room_no', 'name', 'content', 'expire', 'hash'])->Duplicate();
2626
2727 $filter = JinrouCacheManager::Load();
28- $now = Time::Get();
29- $expire = $now + $filter->expire;
30- $filter->next = $expire;
28+ if (CacheConfig::DEBUG_MODE) {
29+ self::OutputTime($filter, 'Insert');
30+ }
3131 $list = [
32- $filter->room_no, $filter->GetName(true), $content, $expire, $filter->hash,
33- $content, $expire, $filter->hash
32+ $filter->room_no, $filter->GetName(true), $content, $filter->next, $filter->hash,
33+ $content, $filter->next, $filter->hash
3434 ];
35- if (CacheConfig::DEBUG_MODE) {
36- self::OutputTime($now, $expire, 'Insert');
37- }
3835
3936 DB::Prepare($query->Build(), $list);
4037 return DB::Execute();
@@ -45,13 +42,10 @@
4542 $query = self::GetQueryUpdate()->Update()->Where(['room_no', 'name']);
4643
4744 $filter = JinrouCacheManager::Load();
48- $now = Time::Get();
49- $expire = $now + $filter->expire;
50- $filter->next = $expire;
51- $list = [$content, $expire, $filter->hash, $filter->room_no, $filter->GetName(true)];
5245 if (CacheConfig::DEBUG_MODE) {
53- self::OutputTime($now, $expire, 'Updated');
46+ self::OutputTime($filter, 'Updated');
5447 }
48+ $list = [$content, $filter->next, $filter->hash, $filter->room_no, $filter->GetName(true)];
5549
5650 DB::Prepare($query->Build(), $list);
5751 return DB::Execute();
@@ -83,8 +77,8 @@
8377 }
8478
8579 //時刻出力 (デバッグ用)
86- private static function OutputTime($now, $expire, $name) {
87- JinrouCacheManager::OutputTime($now, $name);
88- JinrouCacheManager::OutputTime($expire);
80+ private static function OutputTime(JinrouCache $filter, $name) {
81+ JinrouCacheManager::OutputTime($filter->now, $name);
82+ JinrouCacheManager::OutputTime($filter->next);
8983 }
9084 }
Show on old repository browser