Nov 27, 2015
0
Level 29
Redis cache best practice
Hello everyone.
I'm using Redis as caching system and it works great for most of the part, I've a little question tho
I've an index() method which contains this code
$companies = Cache::rememberForever('auth.companies', function () {
return Company::with([
'tags',
'emails'
])->get();
});
This should store the companies inside the key auth.companies, and it works fine. The doubt appears when I try to edit a specific company in update() method like so
$company = Company::whereId($id)->firstOrFail();
$company->update($request->all());
Cache::forget('auth.companies');
My questions are
- When I try to update a specific entity should i work with the cached object or retrieve it from the Database? (which is NOT redis atm)
- If I should work with the cached object how can I persist the data inside the Database?
EDIT: typos
Please or to participate in this conversation.