public function behaviors(){
return [
[
'class'=>'yii\filters\HttpCache',
'lastModified' => function(){
return 23432;//时间戳
}
]
];
}
public function actionIndex(){
return $this->renderPartial('index');
}
另外视图层:index.php
::
<h1>
test of httpcache
</h1>
http缓存个人解答:
第一次请求后,结果会缓存在浏览器中,请求头带上return的时间戳(last-modified),
法①时间对比,last-modified:第二次进行相同请求时,浏览器会带上上一次behaviors中renturn的时间戳,服务器收到后与之比对发现相同,所以返回304状态码,告诉浏览器调用缓存的记录就行
法②内容etag与last-modified结合:先验证last-modified,相同则返回304,不同则验证etag
结果:
1、第一次请求,浏览器输出:test of httpcache
2、把test of httpcache改为:second test
3、再次请求,浏览器依然输出test of httpcache