Browse Source

add exception catch for cache read from file

master
filesite 1 month ago
parent
commit
cab5a5d679
  1. 22
      plugins/Common.php

22
plugins/Common.php

@ -564,15 +564,19 @@ Class Common {
$cache_filename = "{$cacheDir}{$key}.json"; $cache_filename = "{$cacheDir}{$key}.json";
if (file_exists($cache_filename)) { if (file_exists($cache_filename)) {
$jsonData = file_get_contents($cache_filename); try {
$data = json_decode($jsonData, true); $jsonData = file_get_contents($cache_filename);
$data = json_decode($jsonData, true);
//如果缓存没有失效
$now = time(); //如果缓存没有失效
if ($now - $data['ctime'] <= $expireSeconds) { $now = time();
return empty($withCreateTime) ? $data['data'] : $data; if ($now - $data['ctime'] <= $expireSeconds) {
}else { return empty($withCreateTime) ? $data['data'] : $data;
return null; }else {
return null;
}
}catch(Exception $e) {
return false;
} }
} }

Loading…
Cancel
Save