jeudi 7 juillet 2016

When does Laravel clear the cache?

I am trying to utilize Redis with Laravel 5 to cache queries/results to make my application run faster.

However, I have couple of questions which should help me decide when it is a good time to use Cache and when it is not.

Assume I have the following

$interview= Cache::remember('SomeUniqueKey', 180, function(){

    return SurveyInterview::where('user_id', 123)
                          ->with([
                                    'current_step.page',
                                    'pages'
                                ])
                          ->first();
});

The previous code should cache the collection set returned by eloquent. which is a total of 3 queries. First to query the model, second to query the current_step.page relation and the last one to query the pages relation.

It is my understanding that as long as I execute the above code over and over, Laravel will return the collection from the cache until the 180 minutes are up from the time the collection was cached.

Question

Will laravel automatically remove the cache if an update took place to my database tables? In other works, will it remove the cache once I make an update to my SurveyInterview model or will I have to remove that manually every time I update the model?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire