mikebronner / laravel-model-caching

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

Model cache timeout option #401

Closed magnetic5355 closed 3 years ago

magnetic5355 commented 3 years ago

Is your feature request related to a problem? Please describe.

When utilizing applications that can make changes directly in the db or an outside process but you can still return stale data for a period of time, a configuration option is needed to specify cache time on the command and model.

For instance if you have 1000's of hits a minute and you can return stale data that was changed by an outside process for a minute; you can save 1000's of db queries.

Describe the solution you'd like Add option to set cacheTimeout on the model and on the query builder

Describe alternatives you've considered Jobs that clear model cache by model name

mikebronner commented 3 years ago

Hi @caesarcxiv, Thanks for writing in.

The solution for your use-case is to manually flush the cache of the affected model(s) directly after the database updates have completed using the [model name]::flushCache() or $model->flushCache() method, or alternatively using the artisan command

php artisan modelCache:clear --model=App\Model