session 可以用来缓存 laravel 5.3 中的数据吗?
can session be used to cache data in laravel 5.3?
我正在 laravel 5.3 进行一个项目,我需要从我的数据库中获取大数据。所以我现在正在做的是通过查询获取数据,然后将其保存在会话中,这样下次就不需要进一步的数据库查询了。
不知何故这是不好的做法吗?或者任何其他更好的选择,如数据库缓存?
缓存查询的Laravel方式如下:
$value = Cache::remember('users', $minutes, function() {
return DB::table('users')->get();
});
如果该项目不存在于缓存中,将执行传递给 remember 方法的 Closure 并将其结果放入缓存中。
The cache configuration is located at config/cache.php
. In this file you may specify which cache driver you would like used by default throughout your application. Laravel supports popular caching backends like Memcached and Redis out of the box.
我正在 laravel 5.3 进行一个项目,我需要从我的数据库中获取大数据。所以我现在正在做的是通过查询获取数据,然后将其保存在会话中,这样下次就不需要进一步的数据库查询了。
不知何故这是不好的做法吗?或者任何其他更好的选择,如数据库缓存?
缓存查询的Laravel方式如下:
$value = Cache::remember('users', $minutes, function() {
return DB::table('users')->get();
});
如果该项目不存在于缓存中,将执行传递给 remember 方法的 Closure 并将其结果放入缓存中。
The cache configuration is located at
config/cache.php
. In this file you may specify which cache driver you would like used by default throughout your application. Laravel supports popular caching backends like Memcached and Redis out of the box.