您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
6-5 http缓存之etag
发布时间:2023-05-12 21:59:47编辑:雪饮阅读()
-
关于lastModified,当第一次缓存到http缓存中时候会记录该字段lastModified的值。
当第二次请求的时候会服务端中的lastModified与http缓存中的lastModified比对,如果相同,则继续使用http缓存中的响应。
那么除了使用lastModified以外,也可以使用etagSeed,etagSeed不同于lastModified,etagSeed比对的不是时间戳,而是比对的字符[串]内容了。
但是如果说lastModified已经不同了,那么会立即生成最新的响应数据。
如果lastModified和http缓存中的lastModified一致,那么接下来就是比对etagSeed与http缓存中的etagSeed是否相同,如果相同,则继续使用http缓存中的,否则就是重新生成新的响应数据。
是否使用了http缓存,就在于响应码是否304(一般的)
那么lastModified与etagSeed的共同使用实例如:
<?php
namespace app\controllers;
use yii\web\Controller;
class HelloController extends Controller{
public function behaviors()
{
return [
[
'class'=>'yii\filters\HttpCache',
'lastModified'=>function(){
return 14328175645;
},
'etagSeed'=>function(){
return 'etagseed String2456';
}
]
];
}
public function actionIndex(){
return $this->renderPartial('view1');
}
}
关键字词:http缓存,etag