Skip to content

Instantly share code, notes, and snippets.

@HanbitGaram
Created January 8, 2024 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HanbitGaram/56809a9d0c174608a9deb6f4dac4a92e to your computer and use it in GitHub Desktop.
Save HanbitGaram/56809a9d0c174608a9deb6f4dac4a92e to your computer and use it in GitHub Desktop.
그누보드용 간이 캐싱 도구
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
function get_hanbit_cache(string $cacheName, int $cacheTime=5){
$cacheName = preg_replace("#[^a-zA-Z0-9\-\_]#", "", $cacheName);
$file = G5_PATH.'/data/cache/hanbit-cache-'.$cacheName.'-final.bin';
if(!is_file($file)) return false;
$currentTime = time();
$fileTime = filemtime($file);
if($currentTime - $fileTime >= $cacheTime) return false;
return unserialize(file_get_contents($file));
}
function set_hanbit_cache(string $cacheName, $cacheValue){
$cacheName = preg_replace("#[^a-zA-Z0-9\-\_]#", "", $cacheName);
$file = G5_PATH.'/data/cache/hanbit-cache-'.$cacheName.'-final.bin';
$cacheValue = serialize($cacheValue);
file_put_contents($file, $cacheValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment