캐시 라이브러리 파일에 일부 hook 이벤트 추가

This commit is contained in:
thisgun
2021-02-05 11:54:14 +09:00
parent 21db2b46e3
commit 184172a5a6

View File

@ -9,6 +9,8 @@ function get_cachemanage_instance(){
if( ! (defined('G5_USE_CACHE') && G5_USE_CACHE) ) return $instance; if( ! (defined('G5_USE_CACHE') && G5_USE_CACHE) ) return $instance;
$instance = run_replace('get_cachemanage_instance', $instance);
if( $instance === null ){ if( $instance === null ){
$options = array( $options = array(
'_cache_path'=> G5_DATA_PATH.'/cache', '_cache_path'=> G5_DATA_PATH.'/cache',
@ -48,16 +50,24 @@ function g5_latest_cache_data($bo_table, $cache_list=array(), $find_wr_id=0){
function g5_set_cache($key, $save_data, $ttl = null){ function g5_set_cache($key, $save_data, $ttl = null){
if( $cache = get_cachemanage_instance() ){ if( $cache = get_cachemanage_instance() ){
run_event('g5_set_cache_event', $cache, $key, $save_data, $ttl);
if( (is_object($cache) && get_class($cache) === 'FileCache') ){
$cache->save($key, $save_data, $ttl); $cache->save($key, $save_data, $ttl);
} }
}
} }
function g5_get_cache($key, $expired_time=0){ function g5_get_cache($key, $expired_time=0){
if( $cache = get_cachemanage_instance() ){ if( $cache = get_cachemanage_instance() ){
if( (is_object($cache) && get_class($cache) === 'FileCache') ){
return $cache->get($key, $expired_time); return $cache->get($key, $expired_time);
} }
return run_replace('g5_get_cache_replace', false, $cache, $key, $expired_time);
}
return false; return false;
} }
@ -82,6 +92,11 @@ function g5_delete_all_cache(){
} }
function g5_delete_cache_by_prefix($key){ function g5_delete_cache_by_prefix($key){
$cache = get_cachemanage_instance();
$files = null;
if( (is_object($instance) && get_class($instance) === 'FileCache') ) {
$files = glob(G5_DATA_PATH.'/cache/'.$key.'*'); $files = glob(G5_DATA_PATH.'/cache/'.$key.'*');
foreach( (array) $files as $filename){ foreach( (array) $files as $filename){
@ -89,6 +104,9 @@ function g5_delete_cache_by_prefix($key){
unlink($filename); unlink($filename);
} }
}
$files = run_replace('g5_delete_cache_by_prefix', $files, $key);
return ($files) ? true : false; return ($files) ? true : false;
} }