简体   繁体   中英

laravel eloquent model cache

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?

There is a built-in method for this:

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

I hope this helps, although a year later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM