mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.25k stars 212 forks source link

DB Facade Support #286

Closed newalphamedia closed 5 years ago

newalphamedia commented 5 years ago

I've noticed some issues with data becoming static (not updating cache) when using the DB facade for things like inserts and updates. Since my app uses DB queries rather than Model queries in SOME places, I notice that the cache doesn't become invalidated - I assume that is because this package doesn't support this feature?

I'd like to suggest that it is implemented - otherwise I would be forced to not use any DB facade calls when using anything that's on a Model - in some cases it just seems "better" to use the DB facade though, so this would be quite limiting.

If this is already implemented, forgive me - I must simply have an error somewhere in my code.

UPDATE: I should mention that my work-around is to use this line anywhere when an update through DB facade will happen: $exitCode = \Artisan::call("modelCache:clear", ['--model' => 'App\ExampleModel']);

mikebronner commented 5 years ago

Hi @newalphamedia, the very nature of this package prevents it from work on QueryBuilder queries. It will only work on EloquentBuilder queries. While it may seem better to use normal QueryBuilder queries to do things, it's probably not a good idea and may expose your app to technical debt. But that's up to you to decide, of course.

Thanks for writing. Unfortunately this is not a feature we will be implementing. Sorry.