API Resource 缓存没有效果?

使用了 Cache::remember,通过 Telescope 查看缓存的获取和保存都成功了,但是查看 RequestQuery ,数据库的查询语句依然执行了,看的我懵逼了。

目前发现获取 API Resource 缓存的时候,依然会去查询数据库。。。

file

不管是否对 API Resource 进行缓存,发现 Query 查询语句竟然是相同的。。。

api
坚持学习,每天进步!
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2
Epona

Cache::remember 是在哪部分设置的?

5年前 评论
        $seconds = 3600 * 24;
        $cache_key = 'category_'.md5(implode(',', $category_id));
        $category = Cache::remember($cache_key, $seconds, function () use ($category_id) {
            return Category::whereIn('id',$category_id)->get();
        });

        $cache_key = 'categories_resource_'.md5(implode(',', $category_id));
        $data['Category'] = Cache::remember($cache_key, $seconds, function () use ($category) {
            return CategoryResource::collection($category);
        });
        return $this->success($data);

前面 category 的缓存没有问题,没有再执行查询语句
后面对 categoryresource 执行缓存就没有效果

5年前 评论