Cache and Pagination
$page = $request->has('page') ? $request->query('page') : 1;
$user = Cache::rememberForever('user_'.$page, function () use ($course_id) {
return User::where('course_id',$course_id)->pagination('5');
});
I wanna know if a user create or edit,how do I forget cache?
With pagination being very efficient anyway, why even bother with cache for this.
Usually you use cache for data that doesn't change that often.
@amk The method is paginate to pagination i.e.
return User::where('course_id',$course_id)->paginate(5)
So your code would become:
$page = $request->query('page', 1);
$user = cache()->rememberForever("user.{$page}", function () use ($id) {
return User::where('course_id', $id)->paginate(5);
});
@jlrdw So,you mean I shouldn't use Cache if data is usually changed?
@robstar thank you Sir...
If I create new user,how to delete old cache?
Just Type in your cmd.
php artisan cache:clear
Please or to participate in this conversation.