为什么缓存好像没有起作用?
有一个接口,返回的是所有课程列表,关联了2个子表,一共也只有128条数据,为什么我用了缓存之后,请求接口的耗时还是和不使用缓存差不多,比如直接查询是800毫秒,直接从缓存里取也还是800毫秒,而且能明显看到请求接口时cpu的波动,缓存是正常取到值的
代码如下:
public function getList()
{
try {
// $data = Course::with([‘lecturer’, ‘department’])->where(‘status’, 1)->get();
$data = Cache::rememberForever(‘courses’, function () {
return Course::with([‘lecturer’, ‘department’])->where(‘status’, 1)->get();
});
$res = [
“code” => “00”,
“data” => $data
];
return response()->json($res);
,这是4核8G服务器没开opcache ,路由输出hello word时间,几十毫秒应该是本地开启opcache,然后没有网络开销的情况下吧,不然也太快了。
试了下,op开启不带业务能到40,快了快5-8倍。效果还是明显的@chowjiawei
关于 LearnKu
推荐文章: