laravel eloquent model cache

可紊 提交于 2020-06-09 04:11:04

问题


I am learning laravel eloquent in Laravel 5.6.

I have already used database query builder & cache.

Retrieve & Store for Database Query Builder

$value = Cache::remember('users', $minutes, function () {
    return DB::table('users')->get();
});

But i don't know how to cache for eloquent.

Retrieve & Store for Eloquent

$value = Cache::remember('users', $minutes, function () {
        return App\User::all();
    });

Is it correct for eloquent or any other method existing?


回答1:


There is a built-in method for this:

App\User::where(['id' => 1])->cache()

I hope this helps, although a year later.



来源:https://stackoverflow.com/questions/51237161/laravel-eloquent-model-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!