//获取最后一次更新时间
$recomm = Recomm::select('updated_at')->orderBy('updated_at','desc')->first();
if($recomm){
$this->is_cache($recomm->updated_at);//检查缓存是否有效
}
public function is_cache($updated_at){
$last_modified_time = strtotime($updated_at);
$gmt_mtime = gmdate('r', $last_modified_time);
header('ETag: "'.md5($last_modified_time).'"');
header('Last-Modified: '.$gmt_mtime);
header('Cache-Control: no-cache');
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime || str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == md5($last_modified_time)) {
header('HTTP/1.1 304 Not Modified');
exit();
}
}
return true;
}
web304缓存
于 2022-05-13 14:01:20 首次发布
关键词由CSDN通过智能技术生成