mikebronner / laravel-model-caching

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

Ability to remember for X minutes? #175

Closed dmason30 closed 6 years ago

dmason30 commented 6 years ago

Describe the solution you'd like Pretty self explanatory, I have some Models that I may not want to be remembered "forever" it would be good if we could specify the expiry minutes at Model level?

mikebronner commented 6 years ago

Let me ask you why you wouldn't want that? The invalidation routines should make it irrelevant if it is saved forever or not. Could you explain your use-case a bit more?

dmason30 commented 6 years ago

I have some nightly raw queries (CRUD) not using the Model directly due to their complex nature and requirement to be optimised for speed. Although I have just noticed that I could access the Model class and call the flushCache method.. apologies I will close this..

mikebronner commented 6 years ago

Sounds good. You can also flush the cache from the command line, so you could trigger that if you wanted from a script run from a CRON job.

atodd commented 5 years ago

I have a similar scenario. I have an API that only has read access to a database. The API and the application that write to the database do not share caching, therefore writes can not invalidate the cache. Also (in my case), it would not be efficient to flush the cache for an entire model as that could invalidate millions of records.

mikebronner commented 5 years ago

@atodd Unfortunately the way invalidation works is that it always flushes the cache for the models involved in any update, insert, or delete queries. There really is no way around that.