You can remember forever. But when something changes you have to call a forget cache there. Or you cache for a period of time
Am I using Cache correctly?
Just last night I learned about Cache in Laravel, I tried to apply it to my app but I'm not sure if I'm using it in the correct way since I couldn't find a tutorial that does exactly what I need to do.
I have some customers that belong to a store_id same as my User. Since the customers list doesn't change often, I thought I could cache it forever, and update the cache anytime a new customer is added.
Does this code block make sense, or is there a better way to do this?
On customer store() function:
Cache::forget('customers.store_' . auth()->user()->store_id);
Cache::rememberForever('customers.store_'.auth()->user()->store_id, function (){
return Customer::all();
});
(Customer model has a global scope that only returns customers that belong to user's store_id)
My second question is, in case I need to update a column on one of my Customers. Is there a way to update it in the Cache or do I need to forget and rememberForever the same data (Customer::all()) again?
Please or to participate in this conversation.