최신글 캐시 생성 주기 코드 수정

This commit is contained in:
thisgun
2020-03-18 11:55:32 +09:00
parent 94d04817c7
commit bf13cf82ee
3 changed files with 19 additions and 10 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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;