代码如下 | 复制代码 |
function read_static_cache($cache_name) { static $result = array(); if (!empty($result[$cache_name])) { return $result[$cache_name]; } $cache_file_path = 'E:/newWeb/web/test/temp/static_caches/' . $cache_name . '.php'; if (file_exists($cache_file_path)) { include_once($cache_file_path); $result[$cache_name] = $data; return $result[$cache_name]; } else { return false; } } /** * 写结果缓存文件 * * @params string $cache_name * @params string $caches * * @return */ function write_static_cache($cache_name, $caches) { $cache_file_path = 'E:/newWeb/web/test/temp/static_caches/' . $cache_name . '.php'; $content = ""; file_put_contents($cache_file_path, $content, LOCK_EX); } function load_config(){ $data = array(); $data = read_static_cache('shop_config'); if ($data === false){ $rs = Execute('SELECT * FROM size WHERE 1'); while($row=FetchArray($rs)){ $data[$row['sizeID']]['sizeNamec'] = $row['sizeNamec']; $data[$row['sizeID']]['sizeNamee'] = $row['sizeNamee']; $data[$row['sizeID']]['sindex'] = $row['sindex']; } write_static_cache('shop_config', $data); } else{ $data = $data; } return $data; } $data = load_config(); |