mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.26k stars 217 forks source link

Invalidate Cache after bulk insert #194

Closed mrahmadt closed 5 years ago

mrahmadt commented 5 years ago

Hello

In my project I have to insert bulk data to a database table (100 to 400 records) per app user, I use raw SQL with DB:insert() to do the insert (I want to have the insert as fas as possible)

Now the issue is after the bulk insert I'm not able to Invalidate the cache to get the new records.

mikebronner commented 5 years ago

I will look into this over the next few days and see if I can add a command to execute on the model directly. In the meanwhile you can execute the artisan command from inside your code:

artisan()->call("modelCache:clear", ["--model" => <ModelName>::class]);
mrahmadt commented 5 years ago

Many Thanks

mikebronner commented 5 years ago

Also, if you use the insert command on the model, instead of the DB Facade, it should invalidate the cache.

mikebronner commented 5 years ago

@mrahmadt Ah! never mind, I already had the functionality included:

$model->flushCache();

It slipped my mind. Sorry.