我正在Laravel 5.6中学习Laravel eloquent.
I am learning laravel eloquent in Laravel 5.6.
我已经使用过数据库查询构建器 &缓存.
I have already used database query builder & cache.
检索 &用于数据库查询生成器的存储
$value = Cache::remember('users', $minutes, function () {
return DB::table('users')->get();
});
但我不知道如何缓存 eloquent.
But i don't know how to cache for eloquent.
检索 &为 Eloquent 存储
$value = Cache::remember('users', $minutes, function () {
return AppUser::all();
});
eloquent 或任何其他现有方法是否正确?
Is it correct for eloquent or any other method existing?
有一个内置的方法:
AppUser::where(['id' => 1])->cache()
我希望这会有所帮助,尽管一年后.
I hope this helps, although a year later.
这篇关于laravel eloquent 模型缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)