From bf13cf82eeee99410b565790eb05fdf4593e12e4 Mon Sep 17 00:00:00 2001 From: thisgun Date: Wed, 18 Mar 2020 11:55:32 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B5=9C=EC=8B=A0=EA=B8=80=20=EC=BA=90?= =?UTF-8?q?=EC=8B=9C=20=EC=83=9D=EC=84=B1=20=EC=A3=BC=EA=B8=B0=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Cache/FileCache.class.php | 19 +++++++++++++------ lib/cache.lib.php | 4 ++-- lib/latest.lib.php | 6 ++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Cache/FileCache.class.php b/lib/Cache/FileCache.class.php index 529312a5f..e220f6282 100644 --- a/lib/Cache/FileCache.class.php +++ b/lib/Cache/FileCache.class.php @@ -33,9 +33,9 @@ class FileCache * * @param string $id */ - public function get($id) + public function get($id, $expired_time=0) { - $data = $this->_get($id); + $data = $this->_get($id, $expired_time); return is_array($data) ? $data['data'] : FALSE; } @@ -59,7 +59,7 @@ class FileCache } - protected function _get($id) + protected function _get($id, $expired_time=0) { $cache_file_path = $this->get_cache_file_path($id); @@ -68,20 +68,27 @@ class FileCache return FALSE; } + $server_time = defined('G5_SERVER_TIME') ? G5_SERVER_TIME : time(); + try{ $file_contents = file_get_contents($cache_file_path); $file_ex = explode("\n\n", $file_contents); $data = unserialize(base64_decode($file_ex[1])); } catch(Exception $e){ - $data = array('ttl'=>1, 'time'=>time() - 1000); + $data = array('ttl'=>1, 'time'=> $server_time - 1000); } - - if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) + + if ($data['ttl'] > 0 && $server_time > $data['time'] + $data['ttl']) { unlink( $cache_file_path ); return FALSE; } + if ($data['time'] && $expired_time && $data['time'] < ($server_time - $expired_time)){ + unlink( $cache_file_path ); + return FALSE; + } + return $data; } diff --git a/lib/cache.lib.php b/lib/cache.lib.php index b2806d6f7..07b640148 100644 --- a/lib/cache.lib.php +++ b/lib/cache.lib.php @@ -52,10 +52,10 @@ function g5_set_cache($key, $save_data, $ttl = null){ } } -function g5_get_cache($key){ +function g5_get_cache($key, $expired_time=0){ if( $cache = get_cachemanage_instance() ){ - return $cache->get($key); + return $cache->get($key, $expired_time); } return false; diff --git a/lib/latest.lib.php b/lib/latest.lib.php index f374ae899..4d60a0b0a 100644 --- a/lib/latest.lib.php +++ b/lib/latest.lib.php @@ -9,6 +9,8 @@ function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time= global $g5; if (!$skin_dir) $skin_dir = 'basic'; + + $time_unit = 3600; // 1시간으로 고정 if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) { if (G5_IS_MOBILE) { @@ -35,7 +37,7 @@ function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time= if(G5_USE_CACHE) { $cache_file_name = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-".g5_cache_secret_key(); - $caches = g5_get_cache($cache_file_name); + $caches = g5_get_cache($cache_file_name, $time_unit * $cache_time); $cache_list = isset($caches['list']) ? $caches['list'] : array(); g5_latest_cache_data($bo_table, $cache_list); } @@ -90,7 +92,7 @@ function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time= 'bo_subject' => sql_escape_string($bo_subject), ); - g5_set_cache($cache_file_name, $caches, 3600 * $cache_time); + g5_set_cache($cache_file_name, $caches, $time_unit * $cache_time); } } else { $list = $cache_list;