R
R
roxik2017-08-12 16:41:50
caching
roxik, 2017-08-12 16:41:50

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();
});

Are there any best practices?
Or open source projects where you can see implementations of this.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
roxik, 2017-08-14
@roxik

Implemented with the help of lada-cache, the flight is normal!

V
Victor, 2017-08-12
@v_decadence

Yes, everyone seems to do it, simply and clearly.

K
Kirill Nesmeyanov, 2017-08-18
@SerafimArts

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 question

Ask a Question

731 491 924 answers to any question