Hi, Ive been using repositories pattern for my eloquent/db queries. I have to implement Cache::remember at anything that requires caching, plus I need to manually flush the cache if the model is updated.
Example, Each user has a profile.
Normally I will eager load this
$users = $this->userRepo->getUsers(); //in repo User::with('profile')->get();
Well this will run two queries every time. One for the user, another is the eager loaded profile.
Well this is good. But I still need to cache them. Like i stated above, i am doing Cache::remember on all the eloquent queries, and then if a user updated his/her profile, i need to flush the cache.
This is not maintanable at all if my application gets big.
Ive been looking at some observer pattern: http://laravel-tricks.com/tricks/easy-eloquent-relation-cache-management
I also dug into the Model class in Laravel 5.1, noticed upon a model deleted/saved, there will be an event fired.
So anyone here can point me at the correct direction?
Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.