时间:2021-07-01 10:21:17 帮助过:2人阅读
快取? 是指cache吗?
可以这样写,注意,只是提供思路。
'', 'time'=>0)), true);}// 读取cache文件内容$cache = json_decode(file_get_contents($cache_file),true);// cache 未过期if(time()-$cache['time']>=$expire){ $data = file_get_contents($data_file); // 读取数据,这里可以随便写个txt放入内容测试 $cache = array( 'data' => $data, 'time' => time() ); file_put_contents($cache_file, json_encode($cache), true); // 写入cache echo 'read data
';}else{ // cache 已过期 echo 'read cache
'; $data = $cache['data'];}echo $data;?>