I would like to know if it is possible to store the results of a function in cache for each possible outcome.
This is not an exact example below, the real example is a lot more complex and I need to cache the results for speed reasons, but this gives you an idea of what I'm trying to accomplish
For example I have a function that retrieves the users comments:
public function getUserComments(User $user)
{
$comments = DB::table('comments')->where('user_id',$user->id)->get();
return $comments;
}
I need to save all the possible outcomes for each individual user in my system so essentially.
For example if I have 100 users:
foreach ($users as $user) {
$cachedResults [] = $user->getUserComments();
}
Now I have the cached results that are faster to look through: $cachedResults