#Caching strategy question, accessing large relationships thought the application

14 messages · Page 1 of 1 (latest)

south mountain
#

This is more of a general question rather than an issue

I have multiple relationships that i need to access multiple times thought the app to check variables and parameters

Ideally caching it once and directly loading it into the request to access thought the app (example in a middleware, in a controller and a few other functions if nessesary)

What would be the best way to do it? Session? But i also need to do logic on the cached data...
Redis? I wouldn't want to call redis 5-10 times per request only once
A singleton that accesses the cached data? Are singletons even a good idea for a caching strategy?
Something else? I'm looking for suggestions...

wraith pewter
#

Can you provide a typical example of how you get your relationship?

south mountain
#

Lets say Auth::user()->load('relation1', 'relation2', 'relation3', 'relation4.relation4.1.relaton4.2'....);
its around 20-30 relations based on user type

wraith pewter
#

Okay so this might get a little bit too much to save this per users on Redis for sure

#

When you have to access the same data over and over, this is done on the span of a single request right?

south mountain
#

the main issue comes down to loading the company settings and permissions, different company policy per location

wraith pewter
#

Oh I see, then you noticed some duplicate queries because of some policies checks ?

south mountain
#

various verifications and validations on what is available and enabled, as well as permissions

wraith pewter
#

I see

south mountain
wraith pewter
#

To be honest I have to deal with the same issues as you have on my own app and I still didn't found a solution that does not involve breaking a lot of basic Laravel logic

#

I have a lot of policies and sometimes twice three Times re-fetching the user from the table to perform some checks on some relations

#

Curious to know if someone else cracked this, I might ask on Twitter to see if anybody has a clue if this thread is not solved