缓存 Laravel 5.2

Caching in Laravel 5.2

我在做什么

下面是我的数据库查询,它从数据库中获取所有用户。

$Users = \App\Models\User\User_Model::with("Role")->get();

问题

在 MVC CI 中,我们可以像下面那样进行数据库查询缓存 $this->_ci->db->cache_on(); Laravel 5.2 中是否有任何内置方法?




更新

As per the Docs here...我正在编写以下代码来获取和设置缓存

$Categories = \Cache::get('Categories', function() {
    return \App\Models\Skill\Category_Model::all();
});

以上代码不起作用,总是从数据库中获取数据。我错过了什么吗?

这样使用(根据需要修改即可):

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

第一次进入数据库,下次从缓存中加载。使用 $minutes 参数,您可以定义在从数据库中再次获取之前应该缓存多少分钟。

Following is the code if you want to remember it forever.

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