Answer the question
In order to leave comments, you need to log in
How to cache database queries in Laravel?
Hello!
How would you recommend caching database queries in Laravel?
Found from normal only:
$value = Cache::remember('users', $minutes, function () {
return DB::table('users')->get();
});
Answer the question
In order to leave comments, you need to log in
In your example, caching responses, not requests. DB queries are cached only at the prepared statemnents PDO level and there is a suspicion that they are fully used in the kernel anyway.
As for the answers, no one bothers to create, for example, a caching middleware and use tagged caching, passing query arguments there as tags.
For special gourmets, you can create a memoization annotation and by subscribing to container resolve events (for example) check it. Well, or again with the help of a global middleware hung on a web group. Not the point.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question