Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel查询生成器:缓存列表结果_Php_Laravel_Laravel 5_Laravel Query Builder - Fatal编程技术网

Php Laravel查询生成器:缓存列表结果

Php Laravel查询生成器:缓存列表结果,php,laravel,laravel-5,laravel-query-builder,Php,Laravel,Laravel 5,Laravel Query Builder,可以像这样缓存查询结果: $users = DB::table('users')->remember(10)->get(); 但是如何缓存列表结果呢。这不起作用: $roles = DB::table('roles')->lists('title'); // Works, but not cached. $roles = DB::table('roles')->remember(10)->lists('title'); // Not working. 抛出错误:

可以像这样缓存查询结果:

$users = DB::table('users')->remember(10)->get();
但是如何缓存列表结果呢。这不起作用:

$roles = DB::table('roles')->lists('title'); // Works, but not cached.
$roles = DB::table('roles')->remember(10)->lists('title'); // Not working.
抛出错误:

exception 'BadMethodCallException' with message 'Call to undefined method Illuminate\Database\Query\Builder::remember()'

在laravel 5+中删除了
lightlight\Database\Query\Builder::memory()
,您可以使用此选项:

$roles = Cache::remember('roles', 10, function() {
    return DB::table('roles')->lists('title');
});

我希望这将对您有所帮助。

在laravel 5+中删除了
illighted\Database\Query\Builder::memory()
,您可以改用它:

$roles = Cache::remember('roles', 10, function() {
    return DB::table('roles')->lists('title');
});
我希望这对你有帮助