Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DerAndi's avatar

How to handle a lot of user data each request?

Hey,

I'm currently wondering how I should deal with user data and thought I'd get some opinions here.

The situation: Every user on my site has lots of data (and therefore relationships) that are loaded with every request. For example: a title (many to many), a name color (many to many), roles and rights (many to many), profile picture and notifications. All are always displayed in the UI. This currently results in 9 database queries each time a page is accessed by logged-in users. With a traffic of around 2,000 to 3,000 concurrent users, this is clearly too much in my opinion.

I am currently considering whether to cache the auth()->user(). From what I've read, that's not the best idea either.

Do you have any suggestions?

Greetings and thanks for the answers!

0 likes
1 reply
Sinnbeck's avatar

Caching can be a great solution if used right. Just be sure to remove the cache when things change (new color, avatar etc)

You can store it for x seconds and of course clear it on save

$colors = Cache::remember('colors.' Auth::user()->id, $seconds, function () {
    return Auth::user()->colors;
});

Please or to participate in this conversation.